-
Notifications
You must be signed in to change notification settings - Fork 18
URI template to REGEX URL #12
Comments
@graingert, @mnot I took a stab at this, see comments in the PR |
Not ignoring, just busy. I'm hearing a fair bit of interest in defining a profile of uri templates (maybe a new level) that is able to be "reversed" -- i.e., given a URL and a template, you can pull the vars out of the URL. Does that seem like the right approach? |
I like the idea. Is there any notion of what the syntax would be? Or would
|
I'd vote for "semantics for reversing and resolving ambiguities", just wanted to add another use-case. I am working for Apiary; what people are doing here is that they specify a list of resources using URI Templates. It may look like this one (let's not argue about API design):
From this, we generate a simple "mock" server, that replies properly:
Therefore, our use-case isn't "is this URL matching that URI template", but "from this list of defined URI templates with possible multiple matches, which ones is matching this URL best?". Regexp is obviously not sufficient for that. I think this is a non-unique use-case, as this is basically what every webserver/framework would be doing. I am in the process of extracting our test-cases from our codebase, but I wanted to reach out for the interest and correct approach. Basically, what we are doing (and it look like it's working in the wild) is "the template with most matching template segments is considered best". However, we have not supported some things (see the end of this article), but after re-reading the spec, I don't think they should change the algorithm above. Our reference implementation is in JavaScript, but if this is considered the reference URI Template implementation, I don't think there are any problems with porting it over here. What is the best approach here -- suggesting a PR to the test suite with test cases and then the implementation here? |
I think a separate spec with its own test suite would be preferable; it would carve out the features that don't work well with this, and provide the algorithm for matching. Make sense? |
@mnot It definitely does for matching; I think it will/should probably have a "level M" for URI templates as a side-effect. Where should we start with the spec? |
I like "level M" :) Regarding the spec - if you want to start a wiki page on this repo, it should be easy to transform it into an Internet-Draft later... |
OK, I'll try to lay it down. |
Minor refactor of code
In lots of python web frameworks, eg Django, all URI templates are specified with regex parameters
It would be great to steal this feature: http://hannesg.github.io/uri_template/doc/URITemplate/RFC6570.html#to_r-instance_method
So I can do things like
url(uritemplate("download/{tag}/{+version}").as_re()), "myview", name="myname")
The text was updated successfully, but these errors were encountered: