Nodejs各类请求的参数响应

参考:https://cnodejs.org/topic/50a333d7637ffa4155c62ddbnode

1)get方式json

请求/api?username=helloapi

路由相应restful

app.get('/api',function(req,res){
    var fileName = req.query.username;
    res.send(fileName);
})


2)post方式,app

请求/apipost

路由相应spa

app.get('/api/:username',function(req,res){
    var fileName = req.body.username;
    res.send(fileName);
})


3)post一个json3d

请求/apirest

路由相应code

app.get('/api/:username',function(req,res){
    var fileName = req.body;
    res.send(fileName);
})


4)restful方式

请求/api/tom

路由相应

app.get('/api/:username',function(req,res){
    var fileName = req.params.username;
    res.send(fileName);
})
相关文章
相关标签/搜索