-
-
Save cezar-popa/3fa86cb6865057100bbd614cde1e32e8 to your computer and use it in GitHub Desktop.
Reusable Javascript ES6 API module using Axios
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' | |
function httpRequest (method, url, request) { | |
return axios[method](url, request) | |
.then(response => Promise.resolve(response)) | |
.catch(error => Promise.reject(error)) | |
} | |
export default { | |
get (url, request) { | |
return httpRequest('get', url, request) | |
}, | |
delete (url, request) { | |
return httpRequest('delete', url, request) | |
}, | |
post (url, request) { | |
return httpRequest('post', url, request) | |
}, | |
put (url, request) { | |
return httpRequest('put', url, request) | |
}, | |
patch (url, request) { | |
return httpRequest('patch', url, request) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment