-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Support advanced URI Template Syntax [SPR-10505] #15137
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
Comments
Rossen Stoyanchev commented UriTemplate actually delegates to UriComponentsBuilder but I see what you mean. Quite a few options in the spec but I guess we can build a mechanism and then support some or all of them. |
Brian Clozel commented Did you have something in mind? We could even use an existing test suite and the implementation details from the RFC! |
Oliver Drotbohm commented The current UriTemplate uriTemplate = new UriTemplate("/orders{?id}");
assertThat(uriTemplate.getVariableNames(), hasItem("id")); // fails - is "?id" Even if you use the discovered variable names as is, the expansion doesn't work: UriTemplate uriTemplate = new UriTemplate("/orders{?id}");
String variableName = uriTemplate.getVariableNames().get(0);
Map<String, String> parameters = Collections.singletonMap(variableName, "47"); // fails - is "/orders%7B?id%7D"
assertThat(uriTemplate.expand(parameters).toString(), is("/orders?id=47")); |
Rossen Stoyanchev commented I guess we'll know more once we try it. Once we add support for operators it may be just as easy to support all operators. On a quick glance levels 2 and 3 at least look pretty useful. /cc Arjen Poutsma |
Brian Clozel commented Assigned to me for the prototyping phase. We'll figure things out after that. |
Oliver Drotbohm commented We've added support for that in Spring HATEOAS, although in a very limited form. |
Brian Clozel commented Reconsidering this for 4.2. |
Rossen Stoyanchev commented Note that we already support the "/" operator in UrlTag (see #16028) and we'll probably do the same in UriComponentsBuilder (see #17347). |
Rossen Stoyanchev commented After some further looking, a number of differences have emerged. Spring's UriComponentsBuilder parses a URI string into constituent components (host, port, path, etc) after which those components can be modified or completely replaced with builder-style methods. URI variables are then expanded into each component and encoding is applied against each (fully expanded) URI component, each according to its own URI syntax (i.e. whatever characters are allowed will not be encoded). By contrast the RFC provides additional syntax for building up the URI through expressions. Accordingly the required parsing logic is different since the URL structure is not even apparent from the literal parts of the URI template (for example a {?var} will append a query string once expanded). It's two ways of achieving the same thing -- using builder-style methods to build up the URL or relying on variable expressions. Also the RFC approach to encoding is quite different. In the RFC by default when URI variables are expanded all URI reserved characters are encoded. By contrast UriComponents applies encoding within each component one at at time and according to the syntax for that component. We have yet to explore a final solution as well as to receive more votes and comments! It's clear however that it won't be a simple flag in the existing UriComponentsBuilder. Rather it will be a new RfcUriComponentsBuilder that may have some relationship to the existing UriComponentsBuilder, or it may not. |
Rossen Stoyanchev commented Postponing since it's a bit late to achieve this for 4.2. |
Rossen Stoyanchev commented Brian Clozel note that I've updated |
Oliver Drotbohm opened SPR-10505 and commented
There is an updated RFC for URI templates. Would b cool if we could either add features to current
UriTemplate
or come up with a dedicated abstraction.Affects: 3.2.2
Sub-tasks:
Issue Links:
1 votes, 9 watchers
The text was updated successfully, but these errors were encountered: