Last active
May 8, 2022 04:12
-
-
Save Kelin2025/c04fe0095ed9d5ab360ade196b7855da to your computer and use it in GitHub Desktop.
API declaration with and without Apicase
This file contains hidden or 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-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 */ |
This file contains hidden or 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 { 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