Last active
March 30, 2020 01:26
-
-
Save RafaelFigueiredo/53fc1f301a3d7b656c37d61ecbc30875 to your computer and use it in GitHub Desktop.
This file contains 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
// 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