6

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.

lmircetic
  • 73
  • 1
  • 1
  • 4
  • I don't understand. Doesn't simply passing the value of `id` to the route do the job? For example, if `id = 245` you just request the following URL: `/test/245`. – Spack Jarrow Aug 24 '20 at 18:33
  • Yeah it does I was just wondering if there was an interface similar to the query tab for path parameters. – lmircetic Aug 24 '20 at 19:57

5 Answers5

4

You can use this plugin https://insomnia.rest/plugins/insomnia-plugin-path-parameters

it automatically replaces URL path parameters with syntax :foo with values defined in the Query tab by the same name.

  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 22 '21 at 11:05
3

For something like test.com/some-value-replaced try using the Query tab to create an entry some-value-replaced = 1234 and then disable the variable so that it won't get added as a standard query param.

Example Query variable

karloluis
  • 209
  • 2
  • 13
2

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.

fafa.mnzm
  • 561
  • 7
  • 17
2

As @karloluis named is possible doing it without any plugins.

But is quite confusing, and I had trouble finding the right way to do it, so I just try to explain it here for future users.

Just in the URL of the endpoint in the section you want to change to be a request parameter, just start to type "req" and wait for the autocomplete to appear.

List of autocomplete options

In this list you should choose Request --> Query Parameter, so you can configure it in the proper way.

The request param configuration

If you have set a value for the request param in the query list, in my case type you should be able to see it in the preview of the request param.

The variable with value and disabled

Finally, remember to disable the query in the list, so is not duplicated.

The full endpoint configuration

SirMartin
  • 148
  • 1
  • 7
  • And I thought adding path parameters in Postman was confusing (because the table appear only when you type "specificators" in the path), but this takes the cake. Wow!.. And thanks for sharing! – Oleg Kuznetsov Aug 15 '23 at 00:24
1

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.

F'1
  • 324
  • 1
  • 4
  • 1
    Thanks, I was using the req.query method you mentioned but I wanted something that actually used the path param. I didn't know you could add straight to the url I was hoping there would be a cleaner way haha. – lmircetic Aug 24 '20 at 19:01