Nodejs各种请求的参数响应

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

1)get方式

请求/api?username=hello

路由相应

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


2)post方式,

请求/api

路由相应

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


3)post一个json

请求/api

路由相应

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


你可能感兴趣的:(nodejs)