MCPcopy Create free account
hub / github.com/TanStack/query / api

Function api

examples/svelte/ssr/src/lib/api.ts:3–18  ·  view source on GitHub ↗
(customFetch = fetch)

Source from the content-addressed store, hash-verified

1import type { Post } from './types'
2
3export const api = (customFetch = fetch) => ({
4 getPosts: async (limit: number) => {
5 const response = await customFetch(
6 'https://jsonplaceholder.typicode.com/posts',
7 )
8 const data = (await response.json()) as Array<Post>
9 return data.filter((x) => x.id <= limit)
10 },
11 getPostById: async (id: number): Promise<Post> => {
12 const response = await customFetch(
13 `https://jsonplaceholder.typicode.com/posts/${id}`,
14 )
15 const data = (await response.json()) as Post
16 return data
17 },
18})

Callers 2

loadFunction · 0.90
loadFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected