Node JS Make Http Get Request with Parameters Example
Hi,
This article will give you example 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 example.
i will give you two examples, using axios and request npm package for male get http request with parameters using node js. let's see both example with output as bellow:
Example 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
Example 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
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to run node js server on https using self-signed certificate?
- Node JS Express Form Submission Example
- Node JS Mysql Connection Example
- Node JS Multer Rename Uploaded File Example
- React Axios Delete Request Example
- React Axios Post Request Example
- React Axios Get Request Example
- Laravel React JS Axios Post Request Example Tutorial
- How to Download File using Axios Vue JS?
- Vue Axios Post Request Example Tutorial
- File Upload using Vue js Axios PHP Example
- Laravel Vue JS Axios Post Request Example