Open History to see the last commit
1import axios from 'redaxios'
2β
3export class NotFoundError extends Error {}
4β
5const queryURL = 'https://jsonplaceholder.typicode.com'
6β
7export const fetchPosts = async () => {
8 console.info('Fetching posts...')
9 return axios.get(`${queryURL}/posts`).then((r) => r.data.slice(0, 10))
10}
11β
12export const fetchPost = async (postId) => {
13 console.info(`Fetching post with id ${postId}...`)
14 const post = await axios
15 .get(`${queryURL}/posts/${postId}`)
16 .then((r) => r.data)
17β
18 if (!post) {
19 throw new NotFoundError(`Post with id "${postId}" not found!`)
20 }
21β
22 return post
23}