Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to read request payload in node.js?

Not applicable

Please let me know how to read request data in node.js server .

Solved Solved
1 16 23.4K
2 ACCEPTED SOLUTIONS

Reading request payload in Apigee Edge is no different from reading the payload in a regular node.js application. Here is an example of reading payload info.

View solution in original post

Not applicable

AFAIK , you need express/apigee-acces or such modules if we need to get the payload directly but if we want to use node.js to parse the req the only way is as below.

//https://nodejs.org/api/http.html#http_http_createserver_requestlistener

var svr = http.createServer(function(req, resp) {
   var body = "";
  req.on('data', function (chunk) {
    body += chunk;
  });
  req.on('end', function () {
    console.log('body: ' + body);
    var jsonObj = JSON.parse(body);
  console.log(jsonObj.test);
  })
    resp.end('Hello, World!');
});

The problem that pani has is, he is on a release which supports node.js but not apigee-access-module.

@sudheendra1 , @sarthak , Am I missing anything or do you see any issues with the above code to parse request body ?

View solution in original post

16 REPLIES 16