nodejs express 中各种请求中的数据位置 参数位置
express 是一个 nodejs 为框架的优秀的 nodejs web 后台服务框架
expres API: http://expressjs.com/en/4x/api.html 这里说一下 express 框架中的请求,在请求的时候数据是从哪个参数中获取的。
express 请求方式
常用的有这些 post
get
delete
put
比如浏览器前端页面中的请求数据是这样的
{
title: 'this is a title',
content: 'and there is some content'
}
在 put
post
中的请求体会是 json 字符串形式传递的
而在 delete
get
中,会以路径参数的形式传递
那个在各种请求方式中的获取方式如下:
router.post('/add', (req, res, next) => {
req.body.title
})
router.delete('/delete', (req, res, next) => {
req.query.title
})
router.put('/modify', (req, res, next) => {
req.body.title
})
router.get('/list', (req, res, next) => {
req.query.title
})