Testing an API call to messages that has a parameter with Postman

This is my API route in nodejs:

router.get('/reset/:token', function(req, res) {
  User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, function(err, user) {
    if (!user) {
      res.json('Password reset token is invalid or has expired.');
      //return res.j('/forgot');
    }
    res.json('Goed');
  });
});

Now that I want to test this in Postman, I am using this wrong way:

Postman screenshot

Usually I do not work with parameters, how can I check this?

+4
source share
3 answers

2 questions. 1. In the screenshot, the method POST, but your code is waiting for the request GET. 2. Use the the URL: http://localhost:3000/reset/6b.... do not usetoken=

+2
source

You can use URL segment parameters, such as:

URL: http://localhost:3000/reset/:id

And URL parameter:

id= 65bb...

enter image description here

+2
source

, :

localhost:3000/reset/65bb...

, (, Postman), :

router.get('/reset', function(req, res) {
   // In here, use req.query.token instead of req.params.token
}
+1
source

Source: https://habr.com/ru/post/1619113/


All Articles