Skip to content

Routing

Andrew Bullock edited this page Oct 30, 2017 · 2 revisions

Routing

Routing is controlled via [Handle] attributes on the Handler:

[Handle("/some/path")]
sealed class SomePathHandler : Handler

Routing is performed in a similar way to System.Web.Routing, however there are no default route values (these aren't necessary, our Model Binder works).

A Handler can have multiple Handle attributes, however the order you place them in the handler .cs file is not obeyed and therefore shouldn't be relied on.

We don't use any broad, MVC style routes which cover many handlers e.g. /{controller}/{action}/{id}. Each handler has its own, specific route defined. Only parameters specific to the handler are varied per route.

[Handle("/some/path")]
[Handle("/some/other/path")]
sealed class SomePathHandler : Handler

Two handlers can handle the same route, although they should not both handle the same HTTP Methods:

[Handle("/some/path")]
sealed class SomePathGetHandler : Handler
{
    public IResult Get()
    {
        // ...
    }
}

[Handle("/some/path")]
sealed class SomePathPostHandler : Handler
{
    public IResult Post()
    {
        // ...
    }
}

Routes can also contain parameters, which are made available to the HTTP Method handling methods:

[Handle("/some/path/{foo}")]
sealed class SomePathHandler : Handler
{
    public IResult Get(string foo)
    {
        // ...
    }
}

TODO

Clone this wiki locally