Feedback on ASP.NET Web API

Allow the controller to use the Route to match a URI and get the route values.

A RESTful application is actually not supposed to make the client construct URIs. The URIs should come from the server and be entirely opaque to the client.

In this regard, it is entirely to the server to specify relationships between resources in the form of hyperlinking with URIs. It is, however, not simple at this time for a Controller to parse such URI when passed from the client in a PUT or POST method to obtain the route values that were used to create the URI, to map them to the domain layer.

The entire route parsing is hidden away and can only be invoked by passing either a context or a complete HttpRequestMessage.

3 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Dave Van den Eynde shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
completed  ·  Daniel Roth responded  · 

For any request the route data is saved on the request message and can be accessed by calling request.GetRouteData(). You can easily bind parameters in your action methods to route data by name. You can also run routing on any request by first getting the route collection from the configuration and then calling GetRouteData() on the route collection. A full request is required to run routing because routes can match based on any part of the request, not just the URI.

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Dave Van den Eynde commented  ·   ·  Flag as inappropriate

    GetRouteData() requires an HttpContext. Constructing one isn't easy, and looking at the source reveals that _parsedRoute.Match() only uses the request path.

    Another way is to find the route that is expected to work, cast it to IHttpRoute, use IHttpRoute.GetRouteData() with a virtual root and a request message, which seems easier to construct. Then, I'd have to use the returned IHttpRouteData to find the expected routedata in the dictionary.

    Fair enough, I suppose I could come up with some helper methods to take the plumbing off my back.

Feedback and Knowledge Base