Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on May 7, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Dec 13, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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!

  3. spring-projects-issues commented on Dec 13, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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"));
  4. spring-projects-issues commented on Dec 13, 2013

    @spring-projects-issues
    CollaboratorAuthor

    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

  5. spring-projects-issues commented on Dec 16, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

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

  6. spring-projects-issues commented on Jan 16, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Oliver Drotbohm commented

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

  7. spring-projects-issues commented on Sep 17, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

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

  8. spring-projects-issues commented on Feb 24, 2015

    @spring-projects-issues
    CollaboratorAuthor

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

  9. spring-projects-issues commented on May 4, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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.

  10. spring-projects-issues commented on May 14, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

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

  11. spring-projects-issues commented on Mar 3, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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.

  12. added
    status: declined
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions