Can get the POST req.body

Tell us what’s happening:
Hello Guys.

Im working on this third project, but for a still unknown reason, I’m not able to get the data of the req.body of the POST method ("/api/shorturl")

req.body appears as “undefined”

If I call req.body.url (that’s how the URL is being sent on the POST methods according to the index.html file") it says: “TypeError: Cannot read properties of undefined (reading ‘url’)”

I don’t know what I’m missing, I’ve used POST and other methods before and it had worked just fine this way.

Your code so far

The code below is just an example of how I would call the URL to be shortened, but of course is by no means the full code.

// URL shorterner endpoint"/api/shorturl", function (req, res) {

const url = req.body.url;



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: URL Shortener Microservice

Link to the challenge:

Are you using any body parser

1 Like

Thanks a lot for the quick answer, I overlooked this small detail…

1 Like