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? Lik开发者_如何学Goe this
controller/action/id/
Admin/editUser/22
The basic premise is, instead of relying exclusively on the URL to indicate what webpage you want to go to (and just using the one method), it's a combination of VERB and URL.
This way, the same URL, when used with a different verb (such as 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.
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'
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.
it maps HTTP VERBS + URL to a specific action in the controller
Example:
GET /users/1
goes to :
:controller => 'users', :action => 'show'
to see the full mapping, go to the terminal, and type:
rake routes
@edtsech is correct. I would like to add one more thing here.
In the case of update,the method is "POST" with a hidden field which contains the data need to be updated.
So PUT = POST + Hidden field.
精彩评论