Inspired by the rails routing api
- Nested Resources
- Shallow Nesting
- Singular Resources
- Adding Custom Actions
- Form Helper
var map = new RestfulRouteMapper(RouteTable.Routes);
map.Resources<BlogsController>(x =>
{
x.Resources<PostsController>(m =>
{
m.Resources<CommentsController>();
});
});This will give you these routes
| Url | Default Controller | Default Action | Constraints |
| blogs | blogs | index | GET |
| blogs | blogs | create | POST |
| blogs/new | blogs | new | GET |
| blogs/{id}/{action} | blogs | show | GET, action = show,edit,delete |
| blogs/{id} | blogs | update | PUT |
| blogs/{id} | blogs | destroy | DELETE |
| blogs/{blogId}/posts | posts | index | GET |
| blogs/{blogId}/posts | posts | create | POST |
| blogs/{blogId}/posts/new | posts | new | GET |
| blogs/{blogId}/posts/{id}/{action} | posts | show | GET, action = show,edit,delete |
| blogs/{blogId}/posts/{id} | posts | update | PUT |
| blogs/{blogId}/posts/{id} | posts | destroy | DELETE |
| blogs/{blogId}/posts/{postId}/comments | comments | index | GET |
| blogs/{blogId}/posts/{postId}/comments | comments | create | POST |
| blogs/{blogId}/posts/{postId}/comments/new | comments | new | GET |
| blogs/{blogId}/posts/{postId}/comments/{id}/{action} | comments | show | GET, action = show,edit,delete |
| blogs/{blogId}/posts/{postId}/comments/{id} | comments | update | PUT |
| blogs/{blogId}/posts/{postId}/comments/{id} | comments | destroy | DELETE |
Shallow nesting allows you to define nested resources but not have deeply nested urls.
var map = new RestfulRouteMapper(RouteTable.Routes);
map.Resources<BlogsController>(config => config.Shallow = true, blogs =>
{
blogs.Resources<PostsController>(posts =>
{
posts.Resources<CommentsController>();
});
});This will give you routes like these
| Url | Default Controller | Default Action | Constraints |
| blogs | blogs | index | GET |
| blogs | blogs | create | POST |
| blogs/new | blogs | new | GET |
| blogs/{id}/{action} | blogs | show | GET, action = show,edit,delete |
| blogs/{id} | blogs | update | PUT |
| blogs/{id} | blogs | destroy | DELETE |
| blogs/{blogId}/posts | posts | index | GET |
| posts | posts | index | GET |
| posts | posts | index | GET |
| posts | posts | create | POST |
| posts/new | posts | new | GET |
| posts/{id}/{action} | posts | show | GET, action = show,edit,delete |
| posts/{id} | posts | update | PUT |
| posts/{id} | posts | destroy | DELETE |
| posts/{postId}/comments | comments | index | GET |
| comments | comments | index | GET |
| comments | comments | create | POST |
| comments/new | comments | new | GET |
| comments/{id}/{action} | comments | show | GET, action = show,edit,delete |
| comments/{id} | comments | update | PUT |
| comments/{id} | comments | destroy | DELETE |
var map = new RestfulRouteMapper(RouteTable.Routes);
map.Resource<SessionController>();| Url | Default Controller | Default Action | Constraints |
| session | session | create | POST |
| session/new | session | new | GET |
| session/{action} | session | show | GET, action = show,edit,delete |
| session | session | update | PUT |
| session | session | destroy | DELETE |
| session | session | show | GET |
The tests describe the different ways you can use this. See the included sample project to see it in action.