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

Default values in query params #171

Merged
merged 5 commits into from
Sep 13, 2024
Merged

Default values in query params #171

merged 5 commits into from
Sep 13, 2024

Conversation

zth
Copy link
Owner

@zth zth commented Sep 12, 2024

No description provided.

@tsnobip
Copy link
Contributor

tsnobip commented Sep 12, 2024

this is a very common need I have, thanks a lot for tackling it!

I'm just wondering about usability, I often have this issue with common types, couldn't we instead define a default value explicitly?

{ "name": "Members", "path": "members?search=string&first=(int:0)&after=string" }

This syntax is obviously just an example.

Another nice to have feature to generate nicer links would be to get rid of the default values in the URL (might be related to #170 too):
for example

Routes.Member.Route.makeLink(~first=0, ~search="Paul") == "members?search=Paul"

What do you think?

@zth
Copy link
Owner Author

zth commented Sep 12, 2024

this is a very common need I have, thanks a lot for tackling it!

I'm just wondering about usability, I often have this issue with common types, couldn't we instead define a default value explicitly?

{ "name": "Members", "path": "members?search=string&first=(int:0)&after=string" }

This syntax is obviously just an example.

It's a trade off definitely of where to put this. With this approach, it's easy to keep default values for param types in sync over multiple routes without having to keep them updated manually. We also avoid cramming a bunch of ReScript code into the JSON route definition string (query param definitions are already pretty crowded). So that's the reason why I opted to do it like this.

Another nice to have feature to generate nicer links would be to get rid of the default values in the URL (might be related to #170 too): for example

Routes.Member.Route.makeLink(~first=0, ~search="Paul") == "members?search=Paul"

What do you think?

Yeah this would definitely be nice, and thinking a bit about I can't see why this shouldn't be the default case - don't set anything in the URL unless you explicitly pass it when creating the link. That's probably an easy adjustment in the PR.

@zth zth merged commit 60ee186 into main Sep 13, 2024
4 checks passed
@zth zth deleted the default-values-in-query-params branch September 13, 2024 05:16
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.

2 participants