A rails inspired restful routing api for asp .net mvc
C# ASP
Pull request Compare This branch is 4 commits ahead, 300 commits behind restful-routing:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
src
tools
.gitignore
README.textile
Rakefile

README.textile

Restful Routing for ASP .NET MVC

Inspired by the rails routing api

Features

  • Nested Resources
  • Shallow Nesting
  • Singular Resources
  • Adding Custom Actions
  • Form Helper

Nested Resources

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

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

Singular Resources

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

More Information

The tests describe the different ways you can use this. See the included sample project to see it in action.