1

I did this get, with the intention of returning the amount of clients that the application needed, but insomnia only returns that it didn't find the route:

server.get('/consultclients?amount=1', (req,res) =>{
let amount = req.params.amount;

return res.json({amount})
})

Request insomnia: localhost:3003/consultclients?amount=10

I tried with a method that I used to search for an id, but I don't think it's the right method to use, even though it works:

server.get('/consultclients/:amount', (req,res) =>{
let amount = req.params.amount;

return res.json({amount})
})

Request insomnia: localhost:3003/consultclients/10

APACHE
  • 11
  • 1

2 Answers2

2

Try the base path .get('/consultclients', …), and then see if req.query.amount (req.query instead of req.params) is populated when you make your request.

davecardwell
  • 3,380
  • 1
  • 17
  • 15
  • It looks like it was the req.query I really needed, and this route correction worked, thanks! – APACHE Jul 26 '22 at 20:30
1

You are trying to access the search params. You can find them in the req.query in the request object instead of the req.params

This code example should work for you:

server.get('/consultclients', (req,res) =>{
  let amount = req.query.amount;

  return res.json({amount})
})
Lalaluka
  • 910
  • 1
  • 11
  • 16
  • It looks like it was the req.query I really needed, and this route correction worked, thanks! – APACHE Jul 26 '22 at 20:30