MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / fetchAPI

Function fetchAPI

hub/src/lib/api.ts:8–22  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

6 `https://hacker-news.firebaseio.com/v0/${path}.json`
7
8async function fetchAPI<T>(path: string) {
9 const url = path.startsWith('user') ? user(path) : story(path)
10
11 const headers: Record<string, string> = { 'User-Agent': 'chrome' }
12
13 const response = await fetch(url, { headers })
14 const text = await response.text()
15 try {
16 return JSON.parse(text) as T
17 } catch (e) {
18 console.error(`Received from API: ${text}`)
19 console.error(e)
20 throw e
21 }
22}
23
24const mapStories = {
25 top: 'news',

Callers

nothing calls this directly

Calls 4

userFunction · 0.85
storyFunction · 0.85
fetchFunction · 0.50
parseMethod · 0.45

Tested by

no test coverage detected