Skip to content

Instantly share code, notes, and snippets.

@marcelo-ribeiro
Last active December 14, 2021 19:52
Show Gist options
  • Save marcelo-ribeiro/4c39065a02697b05ab1647c54d7173dd to your computer and use it in GitHub Desktop.
Save marcelo-ribeiro/4c39065a02697b05ab1647c54d7173dd to your computer and use it in GitHub Desktop.
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 })
});
import axios from "axios";
const api = axios.create({
baseURL: "https://jsonplaceholder.typicode.com"
});
export default api;
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