Skip to content

Export route parameters as path variables #55

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

Merged
merged 12 commits into from
Dec 16, 2021
Merged

Export route parameters as path variables #55

merged 12 commits into from
Dec 16, 2021

Conversation

johnnybenson
Copy link
Contributor

{param} becomes {{param}} and will match on variables defined for the given Postman environment.

`{param}` becomes `{{param}}`  and will match on variables defined for the given Postman environment.
@andreaselia andreaselia requested a review from tomirons December 14, 2021 16:40
@tomirons
Copy link
Collaborator

@johnnybenson I'm confused on the use case for this PR. Converting the url parameters to a postman variable doesn't make much sense. I have a couple clarifying questions for you.

  1. Are you wanting these to be configurable values?
  2. What about converting them to path variables for postman? i.e. posts/{post} -> posts/:post

@johnnybenson
Copy link
Contributor Author

Ahh cool, I didn't realize Postman gave us path variables. That's clearly much better.

$routeStr = str_replace(['}', '{'], ['', ':'], $route->uri());

Want me to update the PR with something like the above?

FWIW, the UI doesn't highlight path variables for some reason. It's been a while since I've used Postman too. Thanks for the help and the very useful feedback!

image

image

@tomirons
Copy link
Collaborator

Yeah, you can update this PR to do that. I wish they had a better way of highlighting the path variables too.

@tomirons tomirons changed the title Export URL parameters as Postman variables Export route parameters as path variables Dec 14, 2021
@tomirons
Copy link
Collaborator

After comparing this to how postman exports collection, there are a couple more things that need to be ironed out.

  • The url.path needs to contain everything after the base url exploded by /
  • The url.variable needs to contain all of the custom variables from the route

@johnnybenson
Copy link
Contributor Author

        {
            "name": "api/v1/chunks/{address}",
            "request": {
                "method": "GET",
                "header": [
                    { "key": "Accept", "value": "application/json" },
                    { "key": "Content-Type", "value": "application/json" }
                ],
                "url": {
                    "raw": "{{base_url}}/api/v1/chunks/:address",
                    "host": "{{base_url}}/api/v1/chunks/:address",
                    "path": ["api", "v1", "chunks", ":address"],
                    "variable": [{
                        "key": "address",
                        "value": ""
                    }]
                }
            }
        }

@tomirons
Copy link
Collaborator

@johnnybenson I've refactored this whole thing, please take it for a test run and let me know if any issues arise. I did not test this locally. 😅

@johnnybenson
Copy link
Contributor Author

johnnybenson commented Dec 16, 2021

Your version looks much better :) thanks. Testing locally, we also need to replace {var} with :var in the exploded path and then we're all set.

Copy link
Collaborator

@tomirons tomirons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! ❤️

@tomirons tomirons merged commit 326e4c6 into andreaselia:master Dec 16, 2021
@andreaselia
Copy link
Owner

Thank you @johnnybenson for the contribution, and @tomirons for the refactoring ❤️

@johnnybenson johnnybenson deleted the patch-2 branch December 16, 2021 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants