This project is read-only.

Simply Restful Routing

Note - this component is deprecated SimplyRestfulRouting has not been maintained for several years, and as such will not be included in builds of MvcContrib going forward.

The SimplyRestfulRouteHandler allows you to easily create a set of default routes for your application using a restful style for the urls.

General Concepts

REST, as defined by wikipedia, is a pattern for defining and addressing resources on networks like the web. Basically it gives easy, clear, and consistent urls and can actually save you some bandwidth and saves on the number of requests your webserver has to handle.

If you are unfamiliar with the basic idea of routing, check out some of the external resources before continuing. It is important that you understand the basics of how controllers and actions are mapped and views are rendered.

Restful routing defines 8 actions, rails uses 7, but we added an extra delete action so you can be build custom forms to either validate some input or confirm a deletion. The 8 actions can be split into two groups. Read actions or nondestructive actions, and write actions or actions with side effects. You will also notice that the actions have a very close relationship to the CRUD concept of Create, Read, Update, Delete.

The Eight Actions

Action HTTP Method Default Url Description
Index GET [controller] Gets a collection of resources
Show GET [controller]/[id] Gets a single resource identified by id
Edit GET [controller]/[id]/edit Gets a form to edit resources identified by id
Delete GET [controller]/[id]/delete Gets a form to confirm a delete of the resource identified by id
New GET [controller]/new Gets form to a create a new resource
Create POST [controller] Creates the new resource
Update PUT [controller]/[id] Updates the resource identified by id
Destroy DELETE [controller]/[id] Deletes the resource identified by id

The above table shows that we map several actions to the same url, how do we do that? Notice that the HTTP Method is different for each url that is the same. When constructing the routes in MVC we use validation filters on the Method parameter of the route to map the request to the correct action.

This has one side effect, some browsers do not support PUT and DELETE requests. So instead of using javascript hacks we use a simpl form _method hack and the SimplyRestfulRouteHandler. The form method hack requires that regular HTTP POST request get sent and included in the submitted form a field named "_method" with a value of the intended restful http method. So adding that the routing table now looks like this.

Action HTTP Method Form Method Default Url Handler
Index GET [controller] MvcRouteHandler
Show GET [controller]/[id] MvcRouteHandler
Edit GET [controller]/[id]/edit MvcRouteHandler
Delete GET [controller]/[id]/delete MvcRouteHandler
New GET [controller]/new MvcRouteHandler
Create POST [controller] MvcRouteHandler
Update PUT [controller]/[id] MvcRouteHandler
Update POST PUT [controller]/[id] SimplyRestfulRouteHandler
Destroy DELETE [controller]/[id] MvcRouteHandler
Destroy POST DELETE [controller]/[id] SimplyRestfulRouteHandler

Getting Started

Default Routes

Routes with Areas

Advanced Routes

Last edited Apr 4, 2011 at 9:58 AM by JeremyS, version 3


ibsukru Apr 3, 2012 at 4:03 PM 
Are not a part of RESTful apis. They are only helper views for CRUD operations.

JeremyS Apr 4, 2011 at 9:56 AM 

No, it is no longer included. SimplyRestfulRouting had not been updated for a long time, so we decided to drop it from MvcContrib going forward. I've updated the page for clarity.

mmilbourne Apr 2, 2011 at 12:36 AM 
Is the simplyrestfulrounting still apart of the build? It doesn't seem to be in the 3.0.51 release.

geekedout Jan 22, 2009 at 2:00 AM 
Is this still relevant with the Beta release? I'm having some trouble testing routes after using the helper.

kevin_ortman May 13, 2008 at 3:32 AM 
This is almost too easy to use ;) Thank you, Adam.
BTW... I've documented a sample implementation at