0

I am trying to send a body as content-type: text/plain but I am unable to retrieve it in my application. I am doing something like this:

"days": [1, 2],
"time": {
    "to":8,
    "from":12
}

But when i try to access it in my controller it doesn't show anything.

   async testFunction(@Body() body, @Req() req) {
       console.log(req.body)
       console.log(body)
   }

But both logs are blank. How do i get text in body ??

Apoorva Chikara
  • 1
  • 3
  • 18
  • 29

1 Answers1

0

If you are sending a object you could simply use JSON instead of plain text:

POST replace_with_your_endpoint
Content-Type: application/json

{
    "days": [1, 2],
    "time": {
        "to":8,
        "from":12
    }
}

In one of your controllers:

@Post()
postRequest(@Body() body: any) {
  console.log(body) // { days: [ 1, 2 ], time: { to: 8, from: 12 } }
}
Lars Flieger
  • 1,542
  • 7
  • 24