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

api.ts

10 lines363 Bytes

1import type { Post } from './types'
2​
3export const postsAPI = {
4 getPosts: async (limit: number): Promise<Array<Post>> => {
5 const response = await fetch('https://jsonplaceholder.typicode.com/posts')
6 if (!response.ok) throw new Error('Failed to fetch posts')
7 const data = await response.json()
8 return data.filter((x: Post) => x.id <= limit)
9 },