api.ts — astro Source File
Architecture documentation for api.ts, a typescript file in the astro codebase.
Entity Profile
Relationship Graph
Source Code
const story = (path: string) => `https://node-hnapi.herokuapp.com/${path}`;
const user = (path: string) => `https://hacker-news.firebaseio.com/v0/${path}.json`;
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
Functions
Source
Frequently Asked Questions
What does api.ts do?
api.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in api.ts?
api.ts defines 3 function(s): fetchAPI, story, user.
Where is api.ts in the architecture?
api.ts is located at examples/hackernews/src/lib/api.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: examples/hackernews/src/lib).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free