SlideShare uma empresa Scribd logo
1 de 41
REST And rails Chhorn Chamnap YoolkMango 15 - July - 2010
Agenda REST Theory RESTful Rails Case Study Authentication References
REST Theory
REST Introduction REST is a unifying theory for how “distributed hypermedia” systems are best organized and structured. Lesson learnt from developers: CRUD operations correspond to HTTP POST, GET, PUT, and DELETE. Consistent, robust, and understandable. Names identifies resources
Resources A resource is something with identity. a row in adatabase, a physical object, an abstract concept, or a real-world event in progress A resource has a URI.  Possible to have more than one??? Different representations of a resource vary based on their content types. How does the server know which one to send? URI extensions (/users/1.html,/users/1.xml) Content negotiation (Accept-Language, Accept-Charset, Accept-Encoding, or Accept)
Resources (example) GET /orders/124 HTTP/1.1 	Host: www.example.com 	Accept: text/html, application/xhtml+xml, text/*, image/png, image/*, */*
Embrace hyperlinks  Use hyperlinks to related resources.  Provide a reasonable quantity of information and link to further details.
Statelessness REST is stateless. It presents scalibility. Each request carries no state at lower or higher levels. Resource state the internal state that all non trivial resources carry, and it is essential to a web application. Application state (session state) the state of the cli-ent’s interaction with the server keeping this state on the server violates REST principles as it breaks addressability.
HTTP Verbs (HTTP Methods) Verbs correspond to actions on resources. GET HEAD POST PUT DELETE
Safe Methods Safe methods are used for retrieval. never be to perform an update All safe methods are idempotent.
Idempotent Methods GET, HEAD, PUT, and DELETE are idempotent methods. The response (and resource state) is the same, no matter how many times thataction is performed.
HTTP Status Codes Success and failure should be inferred from the HTTP response status not from an error message within the payload. 1xx: Informational 2xx: Success 3xx: Redirection 4xx: Client Error 5xx: Server Error
GET Method Transfers a representation of a resource to the client. Read-only access to a resource. The server must decide to perform an update based on a safe request.
PUT Method Updates a resource with the representation provided in the body. If not exist before, the request creates a new one.
DELETE Method Deletes the resource identified by its URI. Subsequent GET queries to the same URI should return a status code of 410 (Gone) or 404 (Not Found).
POST Method Neither safe nor idempotent Two primary uses: creation of new objects annotation of existing objects The URI of the POST is that of the object’s container or parent. The Location header should point to the URI of the created resource
RESTful Rails
Resource-Based Named Routes Encapsulates all of the Rails CRUD actions into one routing statement map.resources :users
Custom resource routes create custom named routes either to the collection (the parent resource) or the members of the collection (the children). map.resources :people, :collection => { :search => :get }, :member => { :deactivate => :post }
Nested routes map.resources :people do |person| 	person.resources :friends end /people/1/friends /people/1/friends/2 map.resources :people do |person| 	person.resources :friends, :name_prefix => 'person_' end The name _prefix option adds a prefix to the generated routes. person_friends_path and person_friend_path
Nested routes (cont.) map.resources :people map.resources :friends, 		:name_prefix => 'person_', 		:path_prefix => '/people/:person_id‘ path_prefix option will add a prefix to the URIs that the route will recognize and generate.
Singleton resource routes Sometimes, there will be an entity that exists as a singleton. map.resources :users do |user| 	user.resource :account end The resource name is still singular, but the inferred controller name is plural.
ActionView Support The link_to family of helpers can take a :method parameter to define the HTTP method. generate hidden form field for the _method parameter for PUT and DELETE. <%= link_to 'Delete', person_path(@person), :method => :delete %>
Content Types Rails has introduced rich support for rendering different responses based on the content type the client wants, via the respond_to method. respond_to do |format| 	format.html #format.html { render } 	format.xml { render :xml => @product } end respond_to :html, :xml In config/initializers/mime_types.rb Mime::Type.register "image/jpeg", :jpg, [], %w(jpeg)
Content Types (cont.)
Content Types (cont.)
Resourceful session state Alternative to holding session state on the server? Nearly any problem REST developers face, the solution is to model it as a resource.
Case Study
Example
Refactor
Refactor (example)
Refactor (example)
Authentication
Authentication Can we used cookies? Yes, cookies can be used, but mainly for authentication. How to authenticate users in a RESTful way via the browser and other clients?
Authentication (cont.) Use cookies/sessions to store information just for authentication. Use HTTP Basic authentication for other server side clients. For more secure, use secure http.
Authentication (cont.)
Authentication (cont.)
References Advanced Rails Recipes OReilly Advanced Rails Oreilly RESTful Web Services http://ajaxpatterns.org/RESTful_Service

Mais conteúdo relacionado

Mais procurados

Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web ServicesAngelin R
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Representational State Transfer (REST)
Representational State Transfer (REST)Representational State Transfer (REST)
Representational State Transfer (REST)David Krmpotic
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCdigitalsonic
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful ArchitectureKabir Baidya
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTelliando dias
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionseyelliando dias
 
Basic web architecture
Basic web architectureBasic web architecture
Basic web architectureRalu Mihordea
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASGuy K. Kloss
 
REST - Representational state transfer
REST - Representational state transferREST - Representational state transfer
REST - Representational state transferTricode (part of Dept)
 
Best practices for RESTful web service design
Best practices for RESTful web service designBest practices for RESTful web service design
Best practices for RESTful web service designRamin Orujov
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQueryDoncho Minkov
 

Mais procurados (20)

Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
REST Presentation
REST PresentationREST Presentation
REST Presentation
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Representational State Transfer (REST)
Representational State Transfer (REST)Representational State Transfer (REST)
Representational State Transfer (REST)
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful Architecture
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
 
Basic web architecture
Basic web architectureBasic web architecture
Basic web architecture
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
 
REST - Representational state transfer
REST - Representational state transferREST - Representational state transfer
REST - Representational state transfer
 
Best practices for RESTful web service design
Best practices for RESTful web service designBest practices for RESTful web service design
Best practices for RESTful web service design
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Intoduction to php web services and json
Intoduction to php  web services and jsonIntoduction to php  web services and json
Intoduction to php web services and json
 
REST, RESTful API
REST, RESTful APIREST, RESTful API
REST, RESTful API
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 

Destaque

Rails Text Mate Cheats
Rails Text Mate CheatsRails Text Mate Cheats
Rails Text Mate Cheatsdezarrolla
 
Rails 3 generators
Rails 3 generatorsRails 3 generators
Rails 3 generatorsjoshsmoore
 
Ruby on Rails Kickstart 103 & 104
Ruby on Rails Kickstart 103 & 104Ruby on Rails Kickstart 103 & 104
Ruby on Rails Kickstart 103 & 104Heng-Yi Wu
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Railsguide
RailsguideRailsguide
Railsguidelanlau
 
Introducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyIntroducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyNikhil Mungel
 
Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Richard Schneeman
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 

Destaque (11)

Ruby on Rails 101
Ruby on Rails 101Ruby on Rails 101
Ruby on Rails 101
 
Rails Text Mate Cheats
Rails Text Mate CheatsRails Text Mate Cheats
Rails Text Mate Cheats
 
Rails 3 generators
Rails 3 generatorsRails 3 generators
Rails 3 generators
 
Rails01
Rails01Rails01
Rails01
 
Ruby on Rails Kickstart 103 & 104
Ruby on Rails Kickstart 103 & 104Ruby on Rails Kickstart 103 & 104
Ruby on Rails Kickstart 103 & 104
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Railsguide
RailsguideRailsguide
Railsguide
 
Introducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyIntroducing Command Line Applications with Ruby
Introducing Command Line Applications with Ruby
 
Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 

Semelhante a Rest and Rails

Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8Andrei Jechiu
 
[2015/2016] The REST architectural style
[2015/2016] The REST architectural style[2015/2016] The REST architectural style
[2015/2016] The REST architectural styleIvano Malavolta
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJerry Kurian
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Alliance
 
Creating Restful Web Services with restish
Creating Restful Web Services with restishCreating Restful Web Services with restish
Creating Restful Web Services with restishGrig Gheorghiu
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and exampleShailesh singh
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and exampleShailesh singh
 

Semelhante a Rest and Rails (20)

Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
REST Basics
REST BasicsREST Basics
REST Basics
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
[2015/2016] The REST architectural style
[2015/2016] The REST architectural style[2015/2016] The REST architectural style
[2015/2016] The REST architectural style
 
Services Stanford 2012
Services Stanford 2012Services Stanford 2012
Services Stanford 2012
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with Java
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Creating Restful Web Services with restish
Creating Restful Web Services with restishCreating Restful Web Services with restish
Creating Restful Web Services with restish
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 

Mais de Chamnap Chhorn

High performance website
High performance websiteHigh performance website
High performance websiteChamnap Chhorn
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web ArchitectureChamnap Chhorn
 
Principles in Refactoring
Principles in RefactoringPrinciples in Refactoring
Principles in RefactoringChamnap Chhorn
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayChamnap Chhorn
 

Mais de Chamnap Chhorn (6)

Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
 
High performance website
High performance websiteHigh performance website
High performance website
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
 
Principles in Refactoring
Principles in RefactoringPrinciples in Refactoring
Principles in Refactoring
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
 

Último

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Rest and Rails

  • 1. REST And rails Chhorn Chamnap YoolkMango 15 - July - 2010
  • 2. Agenda REST Theory RESTful Rails Case Study Authentication References
  • 4. REST Introduction REST is a unifying theory for how “distributed hypermedia” systems are best organized and structured. Lesson learnt from developers: CRUD operations correspond to HTTP POST, GET, PUT, and DELETE. Consistent, robust, and understandable. Names identifies resources
  • 5. Resources A resource is something with identity. a row in adatabase, a physical object, an abstract concept, or a real-world event in progress A resource has a URI. Possible to have more than one??? Different representations of a resource vary based on their content types. How does the server know which one to send? URI extensions (/users/1.html,/users/1.xml) Content negotiation (Accept-Language, Accept-Charset, Accept-Encoding, or Accept)
  • 6. Resources (example) GET /orders/124 HTTP/1.1 Host: www.example.com Accept: text/html, application/xhtml+xml, text/*, image/png, image/*, */*
  • 7. Embrace hyperlinks Use hyperlinks to related resources. Provide a reasonable quantity of information and link to further details.
  • 8. Statelessness REST is stateless. It presents scalibility. Each request carries no state at lower or higher levels. Resource state the internal state that all non trivial resources carry, and it is essential to a web application. Application state (session state) the state of the cli-ent’s interaction with the server keeping this state on the server violates REST principles as it breaks addressability.
  • 9. HTTP Verbs (HTTP Methods) Verbs correspond to actions on resources. GET HEAD POST PUT DELETE
  • 10. Safe Methods Safe methods are used for retrieval. never be to perform an update All safe methods are idempotent.
  • 11. Idempotent Methods GET, HEAD, PUT, and DELETE are idempotent methods. The response (and resource state) is the same, no matter how many times thataction is performed.
  • 12. HTTP Status Codes Success and failure should be inferred from the HTTP response status not from an error message within the payload. 1xx: Informational 2xx: Success 3xx: Redirection 4xx: Client Error 5xx: Server Error
  • 13. GET Method Transfers a representation of a resource to the client. Read-only access to a resource. The server must decide to perform an update based on a safe request.
  • 14. PUT Method Updates a resource with the representation provided in the body. If not exist before, the request creates a new one.
  • 15. DELETE Method Deletes the resource identified by its URI. Subsequent GET queries to the same URI should return a status code of 410 (Gone) or 404 (Not Found).
  • 16. POST Method Neither safe nor idempotent Two primary uses: creation of new objects annotation of existing objects The URI of the POST is that of the object’s container or parent. The Location header should point to the URI of the created resource
  • 18. Resource-Based Named Routes Encapsulates all of the Rails CRUD actions into one routing statement map.resources :users
  • 19. Custom resource routes create custom named routes either to the collection (the parent resource) or the members of the collection (the children). map.resources :people, :collection => { :search => :get }, :member => { :deactivate => :post }
  • 20. Nested routes map.resources :people do |person| person.resources :friends end /people/1/friends /people/1/friends/2 map.resources :people do |person| person.resources :friends, :name_prefix => 'person_' end The name _prefix option adds a prefix to the generated routes. person_friends_path and person_friend_path
  • 21. Nested routes (cont.) map.resources :people map.resources :friends, :name_prefix => 'person_', :path_prefix => '/people/:person_id‘ path_prefix option will add a prefix to the URIs that the route will recognize and generate.
  • 22. Singleton resource routes Sometimes, there will be an entity that exists as a singleton. map.resources :users do |user| user.resource :account end The resource name is still singular, but the inferred controller name is plural.
  • 23. ActionView Support The link_to family of helpers can take a :method parameter to define the HTTP method. generate hidden form field for the _method parameter for PUT and DELETE. <%= link_to 'Delete', person_path(@person), :method => :delete %>
  • 24. Content Types Rails has introduced rich support for rendering different responses based on the content type the client wants, via the respond_to method. respond_to do |format| format.html #format.html { render } format.xml { render :xml => @product } end respond_to :html, :xml In config/initializers/mime_types.rb Mime::Type.register "image/jpeg", :jpg, [], %w(jpeg)
  • 27. Resourceful session state Alternative to holding session state on the server? Nearly any problem REST developers face, the solution is to model it as a resource.
  • 30.
  • 31.
  • 35.
  • 37. Authentication Can we used cookies? Yes, cookies can be used, but mainly for authentication. How to authenticate users in a RESTful way via the browser and other clients?
  • 38. Authentication (cont.) Use cookies/sessions to store information just for authentication. Use HTTP Basic authentication for other server side clients. For more secure, use secure http.
  • 41. References Advanced Rails Recipes OReilly Advanced Rails Oreilly RESTful Web Services http://ajaxpatterns.org/RESTful_Service