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