Skip to content

Instantly share code, notes, and snippets.

@AaronFlower
Last active December 15, 2017 15:37
Show Gist options
  • Save AaronFlower/fb6f0b4b40c275e35f05127fc6b4ba07 to your computer and use it in GitHub Desktop.
Save AaronFlower/fb6f0b4b40c275e35f05127fc6b4ba07 to your computer and use it in GitHub Desktop.
axios create restful resource api
/**
* create Restful API Resource with axios
*/
function createResource (http, path, actions) {
let resource = {
get: id => http.get(`${path}/${id}`),
save: data => http.post(path, data),
query: params => http.get(path, {params}),
update: data => http.put(path, data),
delete: id => http.delete(path, {id})
}
return Object.assign(resource, actions)
}
export default createResource.bind(null, axios)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment