Home / Function/ getJson() — astro Function Reference

getJson() — astro Function Reference

Architecture documentation for the getJson() function in api.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  7813e698_84f0_1c6b_0965_3d21f4eb733a["getJson()"]
  598c0643_11b3_ec0d_95c2_89292edee2e9["api.ts"]
  7813e698_84f0_1c6b_0965_3d21f4eb733a -->|defined in| 598c0643_11b3_ec0d_95c2_89292edee2e9
  style 7813e698_84f0_1c6b_0965_3d21f4eb733a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

examples/ssr/src/api.ts lines 20–37

async function getJson<T>(incomingReq: Request, endpoint: string): Promise<T> {
	const origin = new URL(incomingReq.url).origin;
	try {
		const response = await fetch(`${origin}${endpoint}`, {
			credentials: 'same-origin',
			headers: incomingReq.headers,
		});
		if (!response.ok) {
			throw new Error(`GET ${endpoint} failed: ${response.statusText}`);
		}
		return response.json() as Promise<T>;
	} catch (error) {
		if (error instanceof DOMException || error instanceof TypeError) {
			throw new Error(`GET ${endpoint} failed: ${error.message}`);
		}
		throw error;
	}
}

Domain

Subdomains

Frequently Asked Questions

What does getJson() do?
getJson() is a function in the astro codebase, defined in examples/ssr/src/api.ts.
Where is getJson() defined?
getJson() is defined in examples/ssr/src/api.ts at line 20.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free