Skip to content

Instantly share code, notes, and snippets.

@RafaelFigueiredo
Last active March 30, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RafaelFigueiredo/53fc1f301a3d7b656c37d61ecbc30875 to your computer and use it in GitHub Desktop.
Save RafaelFigueiredo/53fc1f301a3d7b656c37d61ecbc30875 to your computer and use it in GitHub Desktop.
// read documentation of Axios at https://github.com/axios/axios
// <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> - client-side
//
const axios = require('axios')
const Object = (function(){
const endpoint = "/api/object"
return {
create: function(form_data){
axios.post(endpoint, form_data)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
read: function(id){
// Make a request for a user with a given ID
axios.get(`/${endpoint}?id=${id}`)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
},
update: function(id, form_data){
// Make a request for a user with a given ID
axios.put(`/${endpoint}?id=${id}`, form_data)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
},
delete: function(id){
// Make a request for a user with a given ID
axios.delete(`/${endpoint}?id=${id}`)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
},
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment