views:

84

answers:

3

I have been searching pretty hard for info out on the net to explain exactly what Restful routing is but I haven't had any success. There are a lot of resources but not a who lot make sense to me.

I'm familiar with Ruby On Rails's routing system and well as how Code Igniter and PhpCake route things but is there more to it than having a centralized location where you give out routes based on a directory structure? Like this:

controller/action/id/
Admin/editUser/22

I'd appreciate any help with this, it's had me baffled for months. I just thought of putting it on SO.

Thanks

A: 

One big part of the whole restful thing is that you should use the different HTTP methods to represent different actions.

For example in Rails if you were to send a HTTP Delete to /users/[id] it would signify that you want to delete that user. HTTP Get would retrieve an appropriate representation of the user. HTTP Put can update or create a user.

These are some examples, but since there is no standard for RESTful API's in HTTP this is not correct in all cases.

adamse
A: 

RESTful Rails routes, i think that this shows the principle of REST

/users/       method="GET"     # :controller => 'users', :action => 'index'
/users/1      method="GET"     # :controller => 'users', :action => 'show'
/users/new    method="GET"     # :controller => 'users', :action => 'new'
/users/       method="POST"    # :controller => 'users', :action => 'create'
/users/1/edit method="GET"     # :controller => 'users', :action => 'edit'
/users/1      method="PUT"     # :controller => 'users', :action => 'update'
/users/1      method="DELETE"  # :controller => 'users', :action => 'destroy'
edtsech
A: 

From my understanding, the basic premise is, instead of relying exclusively on the URL to indicate what webpage you want to go to, it's a combination of VERB + URL. That way, the same URL, when used with a different verb (one of GET, PUT, POST, DELETE), will get you to a different page. This makes for cleaner, shorter URLs, and is particularly adapted to CRUD applications, which most web apps are.

JRL