.NET library with simple routing API inspired by express.js for Katana applications.
Owin.Routing is now based on ASP.NET System.Web.Routing.
RouteBuilder Route(this IAppBuilder app, string url)
- injects route to app pipeline.
This class providers fluent API to handlers for specific HTTP verbs (GET, POST, etc).
RouteBuilder methods:
using HandlerFunc = Func<IOwinContext, Task>
RouteBuilder Get(HandlerFunc handler)
- set GET handler.RouteBuilder Post(HandlerFunc handler)
- set POST handler.RouteBuilder Put(HandlerFunc handler)
- set PUT handler.RouteBuilder Patch(HandlerFunc handler)
- set PATCH handler.RouteBuilder Delete(HandlerFunc handler)
- set DELETE handler.
Below is block of test code.
[TestCase("/docs/reports", Result = "reports")]
[TestCase("/docs/reports/1", Result = "reports[1]")]
public async Task<string> Test(string path)
{
using (var server = TestServer.Create(app =>
{
app.Route("docs/{collection}")
.Get(async ctx =>
{
var name = ctx.GetRouteValue<string>("collection");
await ctx.Response.WriteAsync(name);
});
app.Route("docs/{collection}/{id}")
.Get(async ctx =>
{
var col = ctx.GetRouteValue<string>("collection");
var id = ctx.GetRouteValue<string>("id");
await ctx.Response.WriteAsync(string.Format("{0}[{1}]", col, id));
});
}))
{
var response = await server.HttpClient.GetAsync(path);
var s = await response.Content.ReadAsStringAsync();
return s;
}
}