Question: What is request module?
Request is designed to be the simplest way possible to make http/https calls.
Question: How to install request module?
npm install request
Question: How to include request module in node project?
var request = require('request');
Question: Give example of GET http call?
var request = require('request'); request('http://domain.com/ajax.php', function (err, response, body) { if (err) { return console.error('upload failed:', err); } console.log(body); });
Question: Give example of POST http call with parameter?
request({method:'post',url:'http://domain.com/ajax.php', form: {name:'hello',age:25},headers:options}, function (error, response, body) { console.log(body); });
Question: How to send custom header with post method?
var headersOpt = { 'User-Agent': 'request' }; request( { method:'post', url:'http://domain.com/ajax.php', form: {name:'hello',age:25}, headers:headersOpt }, function (error, response, body) { console.log(body); });
Question: How to set cookie with request?
request.cookie('key1=value1')