美文网首页
req.query , req.params and req.b

req.query , req.params and req.b

作者: 9b559869875b | 来源:发表于2017-11-25 21:58 被阅读27次

在express.js的controllers里我们经常看到request.query,

request.params, request.body,这些都是什么意思呢?跟我们用来作请求的url形式有什么关联呢?

https://stackoverflow.com/questions/39175587/request-body-vs-request-params-vs-request-query

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){});

request.params will contain id. 

If I pass a body to this route:

{name:'josh'}

This will be in request.body.

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

?后面带的参数就是request.query

Check out the Express docs.

相关文章

网友评论

      本文标题:req.query , req.params and req.b

      本文链接:https://www.haomeiwen.com/subject/ullnvxtx.html