| 1 | import type { Post } from './types' |
| 2 | |
| 3 | export 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 | }) |