Last active
December 14, 2021 19:52
-
-
Save marcelo-ribeiro/4c39065a02697b05ab1647c54d7173dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import api from 'api.js'; | |
export default endpoint => ({ | |
get: (id = "") => api.get(`${endpoint}/${id}`), | |
create: data => api.post(`${endpoint}`, data), | |
update: ({ id, ...data }) => api.put(`${endpoint}/${id}`, data), | |
patch: ({ id, ...data }) => api.patch(`${endpoint}/${id}`, data), | |
delete: id => api.delete(`${endpoint}/${id}`), | |
filterBy: params => api.get(`${endpoint}`, { params }) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
const api = axios.create({ | |
baseURL: "https://jsonplaceholder.typicode.com" | |
}); | |
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import apiClient from './api-client.js'; | |
const postsApi = apiClient('posts'); | |
export const getPosts = async () => { | |
return await postsApi.get(1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment