Open History to see the last commit
1import type { Post } from './types'
2β
3export const postsAPI = {
4 getPosts: async (): 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 await new Promise((resolve) => setTimeout(resolve, 1000))
8 return await response.json()
9 },
10 getPost: async (id: number): Promise<Post> => {
11 const response = await fetch(
12 `https://jsonplaceholder.typicode.com/posts/${id}`,
13 )
14 if (!response.ok) throw new Error('Failed to fetch post')
15 return await response.json()
16 },
17}