ASP.NET 4 MVC Web API: Documentation for Complex Routing

The web api seems to be suitable only for standard use cases. But I want to make more complex routing, but I can not find documentation for complex routing. If I have more controller, the routes are getting harder.

Can I define some optional parameters with dependencies? Like this:

/api/document/{par1}/{par2}

par1 and par2 should be optional, but par2 should only be consistent if par1 is present.

And are recursive parameters possible?

/api/documents/characteristics/{round/green/red-dots}
/api/documents/characteristics/{square/yellow}
/api/documents/characteristics/{square/yellow/flat}
/api/documents/characteristics/{square/yellow/flat/...}

Is there any detailed documentation for web api routing? The microsoft tutorial is too simple ... I need more information about routing.

, , . [Action] -Attribute , ... . , . web api api?


Edit: :

routes.MapHttpRoute(
           name: "DefaultApi",
            routeTemplate: "api/{mandant}/documents/{id}",
            defaults: new { controller = "documents", id = RouteParameter.Optional }
            );

//routes.MapHttpRoute(
//    name: "DefaultApiWithAction",
//    routeTemplate: "api/{mandant}/documents/{id}/{action}",
//    defaults: new { controller = "documents" }
//    );

:

[AcceptVerbs("get")]
public HttpResponseMessage Get(int id)

[ActionName("file")]
[AcceptVerbs("get")]
public HttpResponseMessage filedownload(int id)

, , , , ... [NoAction], ... -, ? (, , get-document, URL ...) , .

+5
1

global.asax, :

routes.MapRoute(
    "ApiRoute",
    "api/document/{par1}/{par2}",
    new {controller="Document", action="SomeMethod"},
    new {par1 = @"\d+" }
 );

, . par1 , , :

routes.MapRoute(
    "ApiRoute",
    "api/document/{par1}/{par2}",
    new {controller="Document", action="SomeMethod"},
    new {par1 = @"(value1|value2|value3)" }
 );
+8

All Articles