2

My application is in nodejs with express.

Im trying to construct an API which has route param and query param both

below are the things what i have tried

 using **=**

 app.get('/:accountId/accounts/password/update?uniqueCode={uniqueCode}', async function(req, res) {
         //my code here
    }

and

app.get('/:accountId/accounts/password/update?uniqueCode/:uniqueCode', async function(req, res) {
             //my code here
   }

but when I hit this from my postman like below

http://localhost:5000/722/account/password/update?uniqueCode={dfgsfksjfksdhfksj}

I'm getting NOTFOUND error from express in both the ways that I have tried. Can anyone suggest how I can do it.

The JOKER
  • 453
  • 8
  • 21

1 Answers1

2

You've to check the queryParams inside your code :

app.get('/:accountId/accounts/password/update', async function(req, res, next) {
          const accountId = req.params.accoundId;
          const  uniqueCode = req.query.uniqueCode;
         ...
          if (/* checkuniqueCode is not valid */) {
               return next()
           }

 }

Here is the doc : https://expressjs.com/fr/api.html#req.query

BENARD Patrick
  • 30,363
  • 16
  • 99
  • 105
  • exactly what i needed, i knew how to access the query but how the API in get would be constructed I was not finding that. This works. – The JOKER Apr 08 '20 at 10:48