Open History to see the last commit
1import type { Post } from './types'
2β
3export const getPosts = async (
4 limit: number,
5 customFetch: typeof fetch = fetch,
6) => {
7 const response = await customFetch(
8 'https://jsonplaceholder.typicode.com/posts',
9 )
10 const data = (await response.json()) as Post[]
11 return data.filter((x) => x.id <= limit)
12}
13β
14export const getPostById = async (
15 id: number,
16 customFetch: typeof fetch = fetch,
17): Promise<Post> => {
18 const response = await customFetch(
19 `https://jsonplaceholder.typicode.com/posts/${id}`,
20 )
21 const data = (await response.json()) as Post
22 return data
23}