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 return await response.json()
8 },
9 getPost: async (id: number): Promise<Post> => {
10 const response = await fetch(
11 `https://jsonplaceholder.typicode.com/posts/${id}`,
12 )
13 if (!response.ok) throw new Error('Failed to fetch post')
14 return await response.json()
15 },
16}