0

How can I send application/json data through postman, so that i can recieve the same data in nodejs server as req.body. I have tried raw body json in postman which sends the data as application/json, but data is available in server as req.rawBody. I need to get the same in req.body. Is there any such option

Riyas TK
  • 1,231
  • 6
  • 18
  • 32

5 Answers5

3

Click on x-www-form-urlencoded tab and enter the body. Now you can receive the body using req.body in backend.

  • 1
    but here the data is send as x-www-form-urlencoded form. I need the data to be send as application/json – Riyas TK Apr 03 '15 at 12:09
2

First, you must choose an http method that supports a body like "POST", "PUT", or "PATCH". Because "GET" and "DELETE" don't support a body.

Then you choose a data type of "raw" and paste/type your JSON data.

Screenshot of the amazing POSTman!

Rap
  • 6,851
  • 3
  • 50
  • 88
0

This may solve your problem. Did u try this in your main .js file?

  app.use(bodyParser.urlencoded({
     extended: true
  }));
  app.use(bodyParser.json());
Pooja
  • 1
  • 1
0

Simply use following syntax in server file

const bodyParser = require('body-parser') const cors = require('cors'); app.use(cors()) // for crossOrigin Access
app.use(bodyParser.urlencoded({extended: false})) app.use(bodyParser.json())

shubham kapoor
  • 589
  • 6
  • 16
0

If you want to send files with a json you can use the multiform-data in postman. use multer npm extension to get the files and use JSON.parse(request.body) to pars the json and access its fields.

Dyary
  • 777
  • 1
  • 8
  • 19