Skip to content

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

Closed
spring-projects-issues opened this issue Apr 30, 2013 · 11 comments
Closed

Support advanced URI Template Syntax [SPR-10505] #15137

spring-projects-issues opened this issue Apr 30, 2013 · 11 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 30, 2013

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Did you have something in mind?
The RFC describes 3 levels of possible implementations that we could target. Note: our current implementation has both expand/match capabilities; so we should consider upgrading both to the same level of implementation.

We could even use an existing test suite and the implementation details from the RFC!

@spring-projects-issues
Copy link
Collaborator Author

Oliver Drotbohm commented

The current UriTemplate only supports the simple string expansions, none of the other expansions work:

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"));

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Assigned to me for the prototyping phase. We'll figure things out after that.

@spring-projects-issues
Copy link
Collaborator Author

Oliver Drotbohm commented

We've added support for that in Spring HATEOAS, although in a very limited form.

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Reconsidering this for 4.2.
We'll see if we can make this happen!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 24, 2015

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).

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 4, 2015

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.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Postponing since it's a bit late to achieve this for 4.2.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 3, 2016

Rossen Stoyanchev commented

Brian Clozel note that I've updated UriTemplateHandler and related classes (as part of #16275) inserting Javadoc that suggests the possibility to create a custom UriTemplateHandler that plugs in an alternative URI template library. I suggest we resolve this as Won't Fix for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants