Can URI templates be used to match URIs to routes?

前端 未结 2 498
长情又很酷
长情又很酷 2021-02-14 04:04

Frameworks like ASP.NET or Nancy provide a syntax that can be used for specifying routes, such as:

MapRoute(\"/customers/{id}/invoices/{invoiceId}\", ...)
         


        
2条回答
  •  旧巷少年郎
    2021-02-14 04:16

    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
    

    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?

提交回复
热议问题