req.body is coming empty when calling api in postman and application

0

I'm trying to use an api in nodejs but I can not pass the parameters the req.body is empty and I can not 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 retorno = { method: '', uri: '', response: [] };

app.get('/consultarCartaoSus', function (req, res) { 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 clientes ', function (err, response) { if (err) { sql.close(); console.log(err); }; retorno.method = 'GET'; retorno.uri = 'consultarCartaoSus'; retorno.response = response.recordsets;

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

    
asked by anonymous 20.10.2017 / 00:50

1 answer

0

Since you are using the GET method for this route, it is notable that you use the parameters you want to use, so that you can retrieve them in your application. Look at an example of how to retrieve information using the app.get's express :

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