Axios HTTP requests in Node JS Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

Hello Brother, i will show you how to works node js axios https request lesson. step by step explain how to make axios post request in node js. Here you will learn http request in nodejs js axios. i would like to show you axios post request lesson node js. follow bellow step for axios node js post lesson.

here, i will give you post, get, put and delete request using axios in node js lesson. so you can easily use axios https request in node js.

let's see lessons bellow:

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install axios --save

HTTP Post Request:

server.js

const axios = require('axios');

const data = {

first_name: 'Sagor',

last_name: 'Savani',

email: 'hardik@gmail.com'

};

axios.post('https://api.mywebtuts.com/api/users', data)

.then((res) => {

console.log(`Status: ${res.status}`);

console.log('Body: ', res.data);

}).catch((err) => {

console.error(err);

});

HTTP Get Request:

server.js

const axios = require('axios');

const querystring = require('querystring');

const data = {

page: 2,

};

const parameters = querystring.stringify(data);

axios.get('https://api.mywebtuts.com/api/users?'+parameters)

.then((res) => {

console.log(`Status: ${res.status}`);

console.log('Body: ', res.data);

}).catch((err) => {

console.error(err);

});

HTTP Put Request:

server.js

const axios = require('axios');

const data = {

first_name: 'Sagor',

last_name: 'Savani',

email: 'hardik@gmail.com'

};

axios.put('https://api.mywebtuts.com/users/2', data)

.then((res) => {

console.log(`Status: ${res.status}`);

console.log('Body: ', res.data);

}).catch((err) => {

console.error(err);

});

HTTP Delete Request:

server.js

const axios = require('axios');

axios.delete('https://api.mywebtuts.com/api/users/2')

.then((res) => {

console.log(`Status: ${res.status}`);

}).catch((err) => {

console.error(err);

});

thank you very much for following up with me.

Tags

Recent Posts

Related Posts