Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL Path Parameters #834

Closed
sboulema opened this issue May 1, 2020 · 9 comments
Closed

URL Path Parameters #834

sboulema opened this issue May 1, 2020 · 9 comments
Labels
discussion Talking over coding question Further information is requested

Comments

@sboulema
Copy link
Contributor

sboulema commented May 1, 2020

Is your feature request related to a problem? Please describe.
I am trying to convert from Postman to Postwoman. I love that I have a proper API testing tool that I can use on my laptop and on my phone and keep everything in sync!
I do however miss the easy way of setting url path parameters as is possible in Postman.

Describe the solution you'd like
More info on how path parameters work in Postman:

Path parameters form part of the request URL, and are referenced using placeholders preceded by : as in the following example: /customer/:id

https://learning.postman.com/docs/postman/sending-api-requests/requests/#sending-parameters

Describe alternatives you've considered
Either a similar solution with a special character or maybe a dropdown next to the current query parameters to indicate if it is a query or path parameter.

@liyasthomas
Copy link
Member

liyasthomas commented May 1, 2020

Hi @sboulema, Glad you're making use of PW.

  1. To add path parameters, simply choose "Parameters tab" under request section and add parameters.

image

  1. There's also another way to append parameters that is to append parameters along the URL itself. Ex: https://httpbin.org/get?param1=true&param2=false

  2. You can even use Pre-request scripts to add/remove parameters

Read more on Pre-request scripts: https://github.com/liyasthomas/postwoman/wiki/Pre-Request-Scripts.

Hope issue is solved.

@sboulema
Copy link
Contributor Author

sboulema commented May 1, 2020

Thanks for the quick response!

Those parameters are added as query parameters though. I am looking for adding a parameter as part of the url path.

/petstore/pet/:petId

With a parameter petId defined as 42 for example.

Would lead to: /petstore/pet/42 as url.

The current parameters would give me:

/petstore/pet?petId=42 as url.

@liyasthomas
Copy link
Member

liyasthomas commented May 1, 2020

Yep, that's why we've Pre-request scripts which can be use to set environment variable. Check Environments Tab in right sidebar to add/export/import envs.

Read more on Pre-request scripts: https://github.com/liyasthomas/postwoman/wiki/Pre-Request-Scripts

We use <<>> angle-braces (instead of {{}} in Postman) to represent env variables.

image

@sboulema
Copy link
Contributor Author

sboulema commented May 1, 2020

Ah, missed that! Thank you very much 😃

@liyasthomas
Copy link
Member

Disclaimer: I'm too busy living my life I fairly have no enough time to improve the Environment flow. 😄

There'll be bugs. Let me know if you stumbled upon any bugs.

@sboulema
Copy link
Contributor Author

sboulema commented May 1, 2020

Have a problem I am running into...

I set my petId as an env variable using the prerequest script. But now I can't select an env from the list to set other variables cause it would overwrite my request specific env variable.

Production environment:
<<PetstoreHost>>

Request env variable:
<<PetId>>

So either I end up with an environment with all path variables for all endpoints, or an environment foreach endpoint...

Would be nice if the environment appends to the prerequest script instead of overwrite if there are request specific variables. Or the request variables should be saved/configured elsewhere?

Thanks for all the hard work and real life is way more important!

@liyasthomas
Copy link
Member

liyasthomas commented May 1, 2020

Do you believe overwriting current env should be the default action? It's easily possible to append vars to current env - but I suspect everybody should not be expecting that behaviour.
An environment with all path variables for all endpoints would be my choice. Anyways, I'm all ears, open for suggestions.

@liyasthomas liyasthomas added discussion Talking over coding question Further information is requested labels May 1, 2020
sboulema added a commit to sboulema/postwoman that referenced this issue May 2, 2020
@sboulema
Copy link
Contributor Author

sboulema commented May 2, 2020

That was a fun saturday!

I wrote a possible solution to the problem: sboulema@25f014e

PathParameter

It adds a type dropdown to the current parameter list. Based on the type, the parameter either gets included as a query parameter or gets added as an environment variable so it can be used in the current url path template replacement.
Parameters without a type are treated as query parameters so the implementation is backwards-compatible.

This way the parameter gets saved with the request and does not have to be saved with the environment.

Any thoughts or comments ?

If you want I can submit a PR 👍

@liyasthomas
Copy link
Member

@sboulema implementation looks good to me. shoot the PR 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Talking over coding question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants