req.body is coming empty when calling api on Postman and the application

Asked

Viewed 993 times

0

I am consuming an api in nodejs but I cannot pass the parameters req.body is becoming empty and I cannot identify the problem

var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var core_use = require('cors');
var sql = require("mssql");

app.use(core_use()); app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ Extended: true }));

var return = { method: ', Uri: ' sponse: [] };

app.get('/query sql.connect(config, Function (err) { var request = new sql.Request(); console.log(req.body); // query to the database and get the Records '' request.query('select * from clients', Function (err, Response) { if (err) { sql.close(); console.log(err); }; return.method = 'GET'; return.Uri = 'query return.Sponse = Sponse.recordsets;

res.setHeader('Access-Control-Allow-Origin', '*'); res.json(retorno); sql.close(); }); });

1 answer

0


As you are using the GET method for this route it is remarkable that you use the parameters you want to use, to recover them in your application. Note an example of how to retrieve information using the.get app from express:

app.get('/api-teste/:parametro1', (req, res) => {
    var parametro1 = req.params.parametro1;
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.