Node JS Make Http Get Request with Parameters 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,

This article will give you lesson of node js make http get request with parameters. you can understand a concept of node js https request query parameters. you will learn how to make an http get request in node.js. you will learn make http get request nodejs. Let's get started with node js axios http get request lesson.

i will give you two lessons, using axios and request npm package for male get http request with parameters using node js. let's see both lesson with output as bellow:

Lesson 1: HTTP GET Request using Axios

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install axios --save

server.js

const axios = require('axios');

const querystring = require('querystring');

const data = {

page: 2,

};

const parameters = querystring.stringify(data);

axios.get('https://reqres.in/api/users?'+parameters)

.then((res) => {

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

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

}).catch((err) => {

console.error(err);

});

Run App

node server.js

Output

Lesson 2: HTTP GET Request using Request

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install request --save

server.js

const request = require('request');

const querystring = require('querystring');

const parameters = {

page: 2,

};

const get_request_args = querystring.stringify(parameters);

const options = {

url: 'https://reqres.in/api/users?'+get_request_args,

json: true

};

request.get(options, (err, res, body) => {

if (err) {

return console.log(err);

}

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

console.log(body);

});

Run App

node server.js

Output

thank you very much for following up with me.

Tags

Recent Posts

Related Posts