Skip to content

softcraft-development/restful-routing

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A rails inspired restful routing api for asp .net mvc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 85.2%
  • Classic ASP 14.8%