NodeJS: HTTP Request - Response

Sending HTTP GET/POST Request and Response using Node JS.

Code:

var https = require("https");

exports.handler = (events,context,callback) => {
 
 var options = {
   host  :  'hostname',
   port  :  '443',
   path  : 'ifany',
   
   headers: {
    
    'Authorization' : 'Basic' + new Buffer("username" + ':' + "password").toString('base64')
   }
 };
 
 // request
 
 request = https.get(options, function(res){
 
  
  var body = "";
  
  res.on('data', function(data){
   body = body+data;
   
  });
  
  res.on('end', function(){
   
   // response
   
   Response = JSON.parse(body);
   
   console.log(Resposne);
      
  });
  
  callback(null,{
   
   "dialogAction":{
    
    "type": "close",
    "fullfillmentState":"Fullfilled",
    "message":{
     "contentType":"PlainText",
     "content" : "Thank You! A email has been sent."
    }
   }
  });
 });
 
};

Comments

Popular posts from this blog

AWS LEX - Developing a Simple Chat Bot

Connecting Mongo DB with NodeJS

BUILDING A CHAT BOT USING MICROSOFT AZURE BOT SERVICE & LUIS