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
CodePudding user response:
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.
CodePudding user response:
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})
})