I'm new to nodejs, and express, and While combing through some code I came across this, What exactly does it mean? and How do I send a POST request to this (using cURL)?? There are no data-fields specified.
app.post('/', limiter, (req, res, next) => {
let {
token
} = req.body;
if (token) {
return res.send('congrats this is your first post request')
}
res.send('not good');
});
Having used flask I have a general idea about what's going on... But I don't understand this part
let {
token
} = req.body;
Can someone please explain what is going on here? Whatever I try, It isn't accepting any POST request. and isn't returning what I want it to. Please excuse me if this doubt seems too trivial, But I haven't seen this anywhere on the internet.
That is assigning the value of req.body.token
to a variable named token
. The same as doing this:
let token = req.body.token;
If you want to curl
this endpoint your data should be JSON something like this:
curl -H "Content-Type: application/json" \
-X POST \
-d '{"token":"<your token here>"}' \
<your url>