Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

data.ts

15 lines486 Bytes

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