Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Last active May 8, 2022 04:12
Show Gist options
  • Save Kelin2025/c04fe0095ed9d5ab360ade196b7855da to your computer and use it in GitHub Desktop.
Save Kelin2025/c04fe0095ed9d5ab360ade196b7855da to your computer and use it in GitHub Desktop.
API declaration with and without Apicase
import axios from './axios-custom'
export const foo = () => axios.get('/foo/bar/')
export const products = {
get: id =>
axios.get(`/products/${id}`),
save: (data, id = null) =>
axios.post(`/products{id ? `/${id}` : ''}`, data),
delete: id =>
axios.delete(`/products/${id}`)
}
// How to bring it into readable form??
export const uploadFile = data => axios.post('/files/upload/',
data, {
headers: { 'Content-Type': 'multipart/form-data' }
}
)
// someAsyncFunction - any function that will return Promise
export const customCallback = someAsyncFunction
/* etc */
import { Container } from 'apicase'
export default new Container({
services: {
foo: { method: 'GET', url: '/foo/bar' },
// Path stacking temporarily is not supported
// But will be in the next version
products: {
children: {
get: { method: 'GET', url: '/products/:id' },
save: { method: 'POST', url: '/products/:id?' },
delete: { method: 'DELETE', url: '/products/:id' }
}
},
uploadFile: {
method: 'POST',
url: '/files/upload',
headers: { 'Content-Type': 'multipart/form-data' }
},
customCallback: {
callback: someAsyncFunction
}
/* etc */
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment