How can I set req.params in an Insomnia GET request?

Viewed 10526

Hi I don't have any code to show but I was just wondering how I can set parameters in a get request in Insomnia. Basically the paramaters in the url such as this one /test/:id where id is the parameter.

I know that you can add queries but thats not what I am after.

If you need me to provide more information let me know.

3 Answers

In the options above, just bellow the url, there is an option next to the Bearer which is named Query.

You can add any url params you want there and it will show you the url preview above it.

Named route parameters should be specified in URL -- there's no need to specify keys in the request itself, since your app parsing them based on their position in the request.

So if you have a handler for /test/:id route on your server, just request https://url/test/123 from any client (including Insomnia) and use this id from req.params.id in your handler (in Express).

But if you want to have key=value structure in your request, I believe, using Query tab in Insomnia and req.query.id on your server is your only option with GET.

Related