可以URI模板被用来匹配URI的路线? [英] Can URI templates be used to match URIs to routes?
问题描述
像ASP.NET或南西框架提供可用于指定的路线,诸如语法:
Frameworks like ASP.NET or Nancy provide a syntax that can be used for specifying routes, such as:
MapRoute("/customers/{id}/invoices/{invoiceId}", ...)
在ASP.NET路由在两个方向工作。他们可以的匹配的请求URI,如 /用户/ 32 /发票/ 19
来的路线,他们可以解析参数,如 {ID:37,invoiceId:19}
成一个URI。
In ASP.NET routes work in two directions. They can match a request URI such as /customers/32/invoices/19
to a route, and they can resolve parameters such as { id: 37, invoiceId: 19 }
into a URI.
RFC 6570:URI模板也定义了类似的,虽然丰富得多,为的URI规范,经常被用来< STRONG>决心的URI。例如:
RFC 6570: URI Templates also defines a similar, though much richer, specification for URI's that are often used to resolve URI's. For example:
UriTemplate("/customers/{id}/invoices{/invoiceId}{?sort}", { id: 37, invoiceId: 19, sort: 'asc' } )
// returns: /customers/37/invoices/19?sort=asc
我的问题是,在RFC 6570中指定的语法被用来匹配请求的URI的路线?是否有语法这将使模糊的给定URI匹配给定URI模板的一部分吗?是否有支持URI匹配的URI模板的任何库?
My question is, can the syntax specified in RFC 6570 be used to match request URI's to routes? Is there a part of the syntax that would make it ambiguous to match a given URI to a given URI template? Are there any libraries that support matching a URI to a URI template?
推荐答案
我怀疑这将是非常困难的。当然的事像preFIX语法,就不可能以再生原始参数
I suspect it would be very difficult. Certainly things like the prefix syntax would make it impossible to regenerate the original parameters.
有关的东西像路径段扩展
For things like path segment expansion
{/list*} /red/green/blue
你如何知道哪个路径的部分是文字和参数的哪些部分是一部分?有很多在URITemplate规格相当怪异的行为,我怀疑即使它是可能的匹配,这将是相当昂贵的。
How would you know which parts of the path were literals and which parts were part of the parameter? There are lots of fairly freaky behavior in the URITemplate spec, I suspect even if it is possible to match, it would be fairly expensive.
您有兴趣做这个路由的目的是什么?
Are you interested in doing this for the purposes of routing?
这篇关于可以URI模板被用来匹配URI的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!