Implement UriTemplate spec
davidfowl opened this issue · 6 comments
https://tools.ietf.org/html/rfc6570
Need a design for the API shape, strawman here https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/util/UriTemplate.html.
FWIW WCF has this type in .NET Framework https://msdn.microsoft.com/en-us/library/system.uritemplate(v=vs.110).aspx but I'm not sure it implements the spec nor do I know if it's relevant.
Today we have RouteTemplate, TemplateParser and TemplateMatcher. This doesn't implement the RFC but @rynowak tells me it can be converted to a proper URITemplate.
/cc @rynowak @danroth27
The WCF version isn't really close to the 6570 spec. This does though https://github.com/tavis-software/Tavis.UriTemplates and It has 100K nuget downloads so it is fairly well tested. Feel free to ping me if you have questions about the spec.
I can also vouch for Tavis.UriTemplates. I've used it extensively over the years and its never let me down.
@darrelmiller why does the implementation use regex? Does it use it outside of supporting actual regular expressions?
@davidfowl It doesn't use regex for converting a Uri Template into a URL. For that it just walks the characters in the template and outputs the URL character by character. The implementation is pretty much the algorithm described in the spec appendix https://tools.ietf.org/html/rfc6570#appendix-A
However, for attempting to extract parameter values out of a URL based on a template it does use Regex. This is only a partial solution as there are a number of scenarios that have no unambiguous way of extracting parameters. This limitation is called out in RFC6570 https://tools.ietf.org/html/rfc6570#section-1.4
Also this
Some URI Templates can be used in reverse for the purpose of variable
matching: comparing the template to a fully formed URI in order to
extract the variable parts from that URI and assign them to the named
variables. Variable matching only works well if the template
expressions are delimited by the beginning or end of the URI or by
characters that cannot be part of the expansion, such as reserved
characters surrounding a simple string expression. In general,
regular expression languages are better suited for variable matching.
Ugh.
This issue was moved to dotnet/aspnetcore#2690