Matthew Stopa
Matthew Stopa

Reputation: 3865

What is Restful Routing?

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

Upvotes: 14

Views: 16678

Answers (5)

JRL
JRL

Reputation: 78003

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.

Upvotes: 21

Xeeshan
Xeeshan

Reputation: 156

@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.

Upvotes: 0

Brian Joseph Spinos
Brian Joseph Spinos

Reputation: 2244

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

Upvotes: 1

edtsech
edtsech

Reputation: 1167

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'

Upvotes: 14

ase
ase

Reputation: 13471

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.

Upvotes: 2

Related Questions