How to handle HTTP response using Axios

axios.post('/student/12', {
firstName: 'Finn',
lastName: 'Williams'
})
.then((response) => {
console.log(response);
}, (error) => {
console.log(error);
});
{

data: {},
// data is the response that was provided by the server
status: 200,
// status is the HTTP status code from the server response
statusText: 'OK',
// statusText is the HTTP status message from the server response
headers: {},
// headers the headers that the server responded with
// All header names are lower cased

config: {},
// config is the config that was provided to axios for request
request: {}
// request is the request that generated this response
// It is the last ClientRequest instance in node.js(in redirects)
// and an XMLHttpRequest instance the browser

}
axios.get('/student/12')
.then((response) => {
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
});

--

--

--

System Administrator and Full stack web developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Difference in “Final” and “

Declarative approach to oidc-client

Building a complete webapp in django and python — part 2

JavaScript Build Tools and Automation Systems

Remove Vowels from a String — LeetCode 1119

Regular JavaScript “for” Loops: Part 1.

7 Reasons React Native is Going to Be BIG in 2021

JavaScript Array Methods Explained with Emojis

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Himanshu Pratap

Himanshu Pratap

System Administrator and Full stack web developer.

More from Medium

Decode JWT Token in Apache Jmeter

Performance Testing

Oracle MySQL Heatwave — Tips and Hacks

How to integrate Google Authenticator in ASP.Net MVC Project?