Last active
December 15, 2017 15:37
-
-
Save AaronFlower/fb6f0b4b40c275e35f05127fc6b4ba07 to your computer and use it in GitHub Desktop.
axios create restful resource api
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
/** | |
* 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