Axios Promise - Request and Response from the Client
Simple example on how to send a post request from the client and handle the response.
Example
axios.post('/login', { firstName: 'Jack', lastName: 'Johnston' })
.then((response) => {
// Success
console.log(response);
}, (error) => {
// Failure
console.log(error);
});
Further Documentation
// Send a POST request
axios({
method: 'post',
url: '/user/new',
data: {
firstName: 'Joe',
lastName: 'Smith'
}
});
Install instructions
# NPM
npm install axios
-- or --
# Include Script Tag in JS file
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>