Home / Function/ fetchAPI() — astro Function Reference

fetchAPI() — astro Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  2aac621e_cd93_0296_ebe3_9f9142e38764["fetchAPI()"]
  e96daabb_a606_60ff_cb8a_351bf9fc15ce["api.ts"]
  2aac621e_cd93_0296_ebe3_9f9142e38764 -->|defined in| e96daabb_a606_60ff_cb8a_351bf9fc15ce
  6a9ce379_fa62_28e4_507a_dbfa52d836e2["user()"]
  2aac621e_cd93_0296_ebe3_9f9142e38764 -->|calls| 6a9ce379_fa62_28e4_507a_dbfa52d836e2
  ab4174a5_ffb7_6067_b89c_4cc5586fb5e1["story()"]
  2aac621e_cd93_0296_ebe3_9f9142e38764 -->|calls| ab4174a5_ffb7_6067_b89c_4cc5586fb5e1
  style 2aac621e_cd93_0296_ebe3_9f9142e38764 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

examples/hackernews/src/lib/api.ts lines 4–24

export default async function fetchAPI(path: string) {
	const url = path.startsWith('user') ? user(path) : story(path);
	const headers = { 'User-Agent': 'chrome' };

	try {
		let response = await fetch(url, { headers });
		let text = await response.text();
		try {
			if (text === null) {
				return { error: 'Not found' };
			}
			return JSON.parse(text);
		} catch (e) {
			console.error(`Received from API: ${text}`);
			console.error(e);
			return { error: e };
		}
	} catch (error) {
		return { error };
	}
}

Domain

Subdomains

Frequently Asked Questions

What does fetchAPI() do?
fetchAPI() is a function in the astro codebase, defined in examples/hackernews/src/lib/api.ts.
Where is fetchAPI() defined?
fetchAPI() is defined in examples/hackernews/src/lib/api.ts at line 4.
What does fetchAPI() call?
fetchAPI() calls 2 function(s): story, user.

Analyze Your Own Codebase

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

Try Supermodel Free