Why @Body() in Post request is not working properly? [Nest.js]

后端 未结 1 1430
谎友^
谎友^ 2021-01-07 02:29

I\'m starting to learn Nest.js, so I am following an Academind Tutorial (link).

My code is not working as expected when I try to get the body variable w

相关标签:
1条回答
  • 2021-01-07 03:08

    You're sending form-data which NestJS does not correctly parse by default. You can use application/x-www-url-form-encoded or application/json along with the raw option in Postman. The JSON body would look like so:

    {
      "id": "7",
      "title": "Whatever Title",
      "desscription": "whats doc",
      "author": "Me"
    }
    

    And then your server will recognize the body properly. The other option would be to add in a body parser that properly parses form-data. There are several options out there like multer, form-parser, formidable, and others.

    0 讨论(0)
提交回复
热议问题