Node.js/Express routing with get params

后端 未结 2 1224
一生所求
一生所求 2020-12-23 09:02

Let\'s say I have get route like this:

app.get(\'/documents/format/type\', function (req, res) {
   var format = req.p         


        
相关标签:
2条回答
  • 2020-12-23 09:38

    Your route isn't ok, it should be like this (with ':')

    app.get('/documents/:format/:type', function (req, res) {
       var format = req.params.format,
           type = req.params.type;
    });
    

    Also you cannot interchange parameter order unfortunately. For more information on req.params (and req.query) check out the api reference here.

    0 讨论(0)
  • 2020-12-23 09:42

    For Query parameters like domain.com/test?format=json&type=mini format, then you can easily receive it via - req.query.

    app.get('/test', function(req, res){
      var format = req.query.format,
          type = req.query.type;
    });
    
    0 讨论(0)
提交回复
热议问题