request.body vs request.params vs request.query

后端 未结 1 1272
说谎
说谎 2021-01-03 01:33

I have a client side JS file that has:

agent = require(\'superagent\'); request = agent.get(url);

Then I have something like

相关标签:
1条回答
  • 2021-01-03 02:06

    req.params is route parameters, req.body is the actual body of the request, and req.query is any query parameters.

    For example, if I declare this route:

    router.get('/user/:id', function(req, res) {});
    

    req.params will contain id.

    If I pass a body to this route:

    {
      name: 'josh'
    }
    

    This will be in req.body.

    If I pass some query parameters to http://myserver.com/api/user?name="josh", req.query will be { name: 'josh' }.

    Check out the Express docs.

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