Skip to content

izhovkin/Owin.Routing

 
 

Repository files navigation

Build Status Build status NuGet Version NuGet Downloads

Owin.Routing

.NET library with simple routing API inspired by express.js for Katana applications.

Owin.Routing is now based on ASP.NET System.Web.Routing.

API

IAppBuilder Extensions

  • RouteBuilder Route(this IAppBuilder app, string url) - injects route to app pipeline.

RouteBuilder class

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.

Sample code

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;
	}
}

About

Simple routing for OWIN applications inspired by express.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.0%
  • Batchfile 1.2%
  • Other 0.8%