Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/filipw/strathweb.typedrouting
https://github.com/filipw/strathweb.typedrouting
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/filipw/strathweb.typedrouting
- Owner: filipw
- License: mit
- Created: 2014-07-11T08:29:22.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-01T17:50:47.000Z (almost 10 years ago)
- Last Synced: 2024-10-02T16:36:40.267Z (about 1 month ago)
- Language: C#
- Size: 603 KB
- Stars: 16
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Strathweb.TypedRouting
======================A library allowing you to define Web API 2 direct routes using strongly typed, centralized syntax. This allows you to ensure tht whenever you refactor your application, the routes will not break.
### Installation and requirements
`TypedRouting` works only with Web API 2.2+. The abstractions used to build up the library were only introduced in the 2.2 release of the framework. Internally, `TypedRouting` is an implementation of `IDirectRouteProvider` - same mechanism as used by attribute routing.
You can grab the package from Nuget:
install-package Strathweb.TypedRouting
### Usage example
Consider the sample controller:
public class TestController : ApiController
{
public HttpResponseMessage Get()
{
//omitted for brevity
}
public HttpResponseMessage GetById(int id)
{
//omitted for brevity
}
}You define the routes to this controller with `TypedRouting` using the following syntax:
var config = new HttpConfiguration();
config.EnableTypedRouting();
config.TypedRoute("test", c => c.Action(x => x.Get()));
config.TypedRoute("test/{id:int}", c => c.Action(x => x.GetById(Param.Any())));You can use the fluent API to give the route a name (so that you can use it with `UrlHelper` and other libraries requiring you to reference routes by name:
config.TypedRoute("test", c => c.Action(x => x.Get().Name("getTest"));
`TypedRouting` works well with `UrlHelper` and with [Drum](https://github.com/pmhsfelix/drum)### Blog post
[Read more](http://www.strathweb.com/2014/07/building-strongly-typed-route-provider-asp-net-web-api/) at my blog
### License
2014 Filip W [MIT](https://github.com/filipw/Strathweb.TypedRouting/blob/master/LICENSE)