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