-
Notifications
You must be signed in to change notification settings - Fork 40
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
Query Parameters shouldn't be mandatory? #14
Comments
Any thoughts on this one? |
👍 for this issue. It would be great if the query params could be optional, maybe using the same [] syntax as optional params in dart:
Meaning name is required but will still match if price, id, or sort do not exist. |
I'll take a look and see if there is a way to fit this in the syntax. We can't invent new syntax and stay compatible with URI Templates. |
I don't immediately see a nice way to express this in the syntax so that you can individually define optional query parameters. But I do see a few options, not all excelusive:
The problem here is that we might want to support the explode operator for grouping multiple values for the same key:
The one question I have is whether optional parameters need to be in the template. Can they just be retrieved from the original Uri? |
Personally I like being more declarative with my URI templates, but retrieving additional parameters from the URI even if they are not defined would also work for me. |
Thanks @justinfagnani Unfortunately, the spec only seems to deal with expansion and not matching. For expansion it seems to treat variables as optional
so one could make a tenuous case that the same approach should be applied to matching but then that would also mean matching missing path segments which is not what I want ;-) You're right in that optional parameters don't "need" to be in the template but I personally really like them there. They help document the API. For example
expresses the API more clearly than
just like the dart function
expresses it's API much better than
Of course |
Yeah, I know the spec doesn't deal with matching, this whole thing is me trying to shoehorn matching in in a reasonable way so that you don't need two sets of URI templates. I'm not sure what you mean by "shelf_route could still include the parameters in the uri template and avoid passing them to uri and instead match them itself". Do you mean pre-processing the UriTemplate to extract the parameter expressions? I agree that this is logic that shouldn't have to be done by a client of uri. If an extra argument to match would work, I think we can do that. The problem I see there is that it turns off query parameter matching as a whole - there's no control per parameter. |
Well I'm glad you did as the matching is at least as valuable as the expansion. Yes I mean that BTW I don't want to turn off matching on parameters but rather have it not fail if one or more of the parameters are not in the uri being matched. I still want the values that do match to be populated in I realise that it would not be per parameter as the spec defines no way to declare a parameter as optional. That's not a big deal for me as other frameworks downstream from
|
BTW your drone build badge is showing as failing |
Picking this up again, I think the best option is to add a parameter to This approach should be forward compatible if we find a way to make parameters optional/required on an individual basis in the template. |
That sounds good to me. Another option to a bool saying if all query params matched you could expose an Iterable of unmatched query params, or of those that did match (depending on your preference). There is already a Map called parameters that seems to relate to this. Not sure how that would fit |
|
One detail is to work out the exact semantics of this new parameter. Does it make all parameters optional, or just query parameters? Path parameters probably shouldn't be optional, but I have seen some schemes where key/value pairs are encoded in paths and fragments. Right now Thinking this through could lead to another solution: a constructor parameter on |
Sounds gtm |
@Andersmholmgren any chance you can do the PR for this? |
I think if there is just the one bool parameter then it should only apply to query params. If we want to support optional path params (which I don't think there is a major case for) then it needs to be kept separate. Either another bool param or the param needs to be more like an enum |
haha yeah I had already resigned to doing it myself although I must admit you "picking this up again" had me all excited ;-) |
This goes to why a constructor param on |
Yeah, sorry about that. I've moved to Polymer full-time, and while I'd like to have time to maintain all my Dart packages, I just don't have enough to do it right. I can certainly help here and there and do reviews though! |
Actually yes I see what you mean by a ctr to I think that is the cleaner option and will approach it that way. thanks Ah time. Something we could all do with more of ;-) |
Awesome! Let me know if you need any help, I know the guts of matching are a little uglier than I would like. I can always look at a branch. |
fyi about to start dev on this now |
How's the patch coming along? |
With the merge of #23, I think this issue was resolved, right? |
It seems unintuitive to fail a match when query parameters are missing.
e.g. a route like
curl -X GET '/search' would fail to match but that is not what I would consider typical behaviour. You normally want the request to match and the
name
parameter to be null.The text was updated successfully, but these errors were encountered: