req.body empty on posts when testing API with postman

If you suddenly discover that the req.body of your nodejs API setup is empty when testing your API with postman, i recommend you double check that the content-type specified by postman corresponds to the content-type of the data you are posting.

For instance i was testing my updateTask API; my updateTask API expects JSON data, but the content type in postman is set to Text/Plain by default and i did not notice in time. Every time i tried updating record, nothing happened until i discovered that the req.body was empty each time i tried.

Click the small arrow pointing down where you see the marker in the image above in your postman to change the data type to the type of data you are dealing with – that should also change your content-type.

For instance if you are sending JSON data, choose JSON and then if you click on headers,

you will see that the content-type has changed to application/json.

So just go ahead and change the data type to the type of data that you are trying to send and the req.body will cease to send empty value.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like