SlideShare une entreprise Scribd logo
1  sur  14
ROUTES AND CONTROLLERS
ROUTES

• Abstract literal URLs from code
• The mapping between URLs and code, serves two purposes:
  • Recognize URLs and trigger a controller action
  • Generate URLs from names or objects, so you don’t have to
    hard code them in views
REST

• Representational State Transfer (REST)
• Architecture Pattern
• Supports Distributed Hypermedia
  such as the World Wide Web
• Roy Fielding, 2000
CLIENT - SERVER
STATELESS
CACHE
UNIFORM INTERFACE
REST

•   client-server
•   stateless communication
•   uniform interface between components
•   separation of concerns
    between UI and data storage
RAILS REST HELPERS
in routes.rb
resources :people



$ rake routes
people GET
 
       /people(.:format)      
 
     {:action=>"index", :controller=>"people"}
people POST
 
      /people(.:format)      
 
 {:action=>"create", :controller=>"people"}
new_person GET
     /people/new(.:format) 
{:action=>"new", :controller=>"people"}
edit_person GET
    
   /people/:id/edit(.:format)
{:action=>"edit", :controller=>"people"}
person GET
 
       /people/:id(.:format) 
 {:action=>"show", :controller=>"people"}
person PUT
 
       /people/:id(.:format) 
 {:action=>"update", :controller=>"people"}
person DELETE
      
   /people/:id(.:format) 
 {:action=>"destroy", :controller=>"people"}
DEFAULT REST
Index
The index action  provides a list of all the resources of a specific type
Sample URL: http://localhost:3000/people
HTTP GET
Defualt web page: index.html

Show
The show action displays the details of a specific resources, by default identified by its ID
Sample URL: http://localhost:3000/people/42
HTTP GET
Defualt web page: show.html
DEFAULT REST
New
The new action displays the a form for creating a new object
Sample URL: http://localhost:3000/people/new
HTTP GET
Defualt web page: new.html

Create
The create action accepts the form fields as parametrs to create a new model
Sample URL: http://localhost:3000/people
HTTP POST
no corresponding web page (re-directs to show.html to display the newly created object)
DEFAULT REST
Edit
The edit action displays the a form for modifying a specific object
Sample URL: http://localhost:3000/people/42/edit
HTTP GET
Defualt web page: edit.html

Update
The update action accepts form fields as parametrs to modify the attributes of a model
Sample URL: http://localhost:3000/people/42
HTTP PUT
no corresponding web page (re-directs to show.html to display the modified object)
DEFAULT REST
Delete
The delete action destroys a specific model
Sample URL: http://localhost:3000/people/42
HTTP DELETE
Routes Controllers

Contenu connexe

Tendances

Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
Aren Zomorodian
 

Tendances (13)

Services Stanford 2012
Services Stanford 2012Services Stanford 2012
Services Stanford 2012
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
Modulo para conectar un programa en vb 6
Modulo para conectar un programa en vb 6Modulo para conectar un programa en vb 6
Modulo para conectar un programa en vb 6
 
Redux as a state container
Redux as a state containerRedux as a state container
Redux as a state container
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Java script objects
Java script objectsJava script objects
Java script objects
 
Ajax
Ajax Ajax
Ajax
 
User Interface
User InterfaceUser Interface
User Interface
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
Managing states
Managing statesManaging states
Managing states
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Neo4j Makes Graphs Easy
Neo4j Makes Graphs EasyNeo4j Makes Graphs Easy
Neo4j Makes Graphs Easy
 

Similaire à Routes Controllers

Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
SharePoint Saturday NY
 

Similaire à Routes Controllers (20)

Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Rest
RestRest
Rest
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Ws rest
Ws restWs rest
Ws rest
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8RestFul Web Services In Drupal 8
RestFul Web Services In Drupal 8
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
Restful Services With WFC
Restful Services With WFCRestful Services With WFC
Restful Services With WFC
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Building Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel AppelBuilding Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel Appel
 
Full Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R StackFull Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R Stack
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 

Plus de Blazing Cloud

RSpec Quick Reference
RSpec Quick ReferenceRSpec Quick Reference
RSpec Quick Reference
Blazing Cloud
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Blazing Cloud
 

Plus de Blazing Cloud (20)

Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3
 
Rails Class Intro - 1
Rails Class Intro - 1 Rails Class Intro - 1
Rails Class Intro - 1
 
Your first rails app - 2
 Your first rails app - 2 Your first rails app - 2
Your first rails app - 2
 
RSpec Quick Reference
RSpec Quick ReferenceRSpec Quick Reference
RSpec Quick Reference
 
Extending rails
Extending railsExtending rails
Extending rails
 
2day Ruby Class Intro
2day Ruby Class Intro2day Ruby Class Intro
2day Ruby Class Intro
 
Mobile Lean UX
Mobile Lean UXMobile Lean UX
Mobile Lean UX
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
Interactive Graphics w/ Javascript, HTML5 and CSS3
Interactive Graphics w/ Javascript, HTML5 and CSS3Interactive Graphics w/ Javascript, HTML5 and CSS3
Interactive Graphics w/ Javascript, HTML5 and CSS3
 
Form helpers
Form helpersForm helpers
Form helpers
 
Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)
 
What you don't know (yet)
What you don't know (yet)What you don't know (yet)
What you don't know (yet)
 
Introduction to Rails
Introduction to RailsIntroduction to Rails
Introduction to Rails
 
ActiveRecord
ActiveRecordActiveRecord
ActiveRecord
 
Ruby on Rails Class intro
Ruby on Rails Class introRuby on Rails Class intro
Ruby on Rails Class intro
 
Ruby on rails toolbox
Ruby on rails toolboxRuby on rails toolbox
Ruby on rails toolbox
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Active Record
Active RecordActive Record
Active Record
 
Enumerables
EnumerablesEnumerables
Enumerables
 

Routes Controllers

  • 2. ROUTES • Abstract literal URLs from code • The mapping between URLs and code, serves two purposes: • Recognize URLs and trigger a controller action • Generate URLs from names or objects, so you don’t have to hard code them in views
  • 3. REST • Representational State Transfer (REST) • Architecture Pattern • Supports Distributed Hypermedia such as the World Wide Web • Roy Fielding, 2000
  • 8. REST • client-server • stateless communication • uniform interface between components • separation of concerns between UI and data storage
  • 9. RAILS REST HELPERS in routes.rb resources :people $ rake routes people GET /people(.:format) {:action=>"index", :controller=>"people"} people POST /people(.:format) {:action=>"create", :controller=>"people"} new_person GET /people/new(.:format) {:action=>"new", :controller=>"people"} edit_person GET /people/:id/edit(.:format) {:action=>"edit", :controller=>"people"} person GET /people/:id(.:format) {:action=>"show", :controller=>"people"} person PUT /people/:id(.:format) {:action=>"update", :controller=>"people"} person DELETE /people/:id(.:format) {:action=>"destroy", :controller=>"people"}
  • 10. DEFAULT REST Index The index action  provides a list of all the resources of a specific type Sample URL: http://localhost:3000/people HTTP GET Defualt web page: index.html Show The show action displays the details of a specific resources, by default identified by its ID Sample URL: http://localhost:3000/people/42 HTTP GET Defualt web page: show.html
  • 11. DEFAULT REST New The new action displays the a form for creating a new object Sample URL: http://localhost:3000/people/new HTTP GET Defualt web page: new.html Create The create action accepts the form fields as parametrs to create a new model Sample URL: http://localhost:3000/people HTTP POST no corresponding web page (re-directs to show.html to display the newly created object)
  • 12. DEFAULT REST Edit The edit action displays the a form for modifying a specific object Sample URL: http://localhost:3000/people/42/edit HTTP GET Defualt web page: edit.html Update The update action accepts form fields as parametrs to modify the attributes of a model Sample URL: http://localhost:3000/people/42 HTTP PUT no corresponding web page (re-directs to show.html to display the modified object)
  • 13. DEFAULT REST Delete The delete action destroys a specific model Sample URL: http://localhost:3000/people/42 HTTP DELETE