add extension to populate path variables with request parameters #1307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an extension to use request parameters to populate path variables. Used parameters are removed so they won't be sent in the query string or body anymore. Unrecognised variables are just ignored leaving the placeholder as it is.
For example, this:
would invoke the URL
/items/42?foo=bar
.Motivation is mainly that it's more or less just an API design choice whether to use query parameters, path variables, or both. When the API is under your own control and a "backend for frontend" kind of an API not meant to be used in other ways, you can of course make the decision to use just query parameters. But when interacting with external or more general APIs also path variables are often needed.
It might be nicer if Htmx supported this out-of-the-box as suggested in #1202 , but this extension provides a usable alternative.
What do you think? Any suggestions for improvements? Any ideas for a better name for the extension?