SlideShare a Scribd company logo
REST & Rails
Web Services for the Rails World
      Rein Henrichs http://reinh.com
self.werewolf? # => false
REST & Rails
•   What Is REST?
•   Make Rails RESTful
•   Eating RESTfully
•   RESTful Tips & Tricks
•   RESTful Resources
What is REST?

Representational

State

Transfer

Of Resources
Resources
•   Sources of specific information
•   Identified by a global identifier (URI)
•   Hyperlinked to other resources
•   Examples:
    •   del.icio.us tags, links
    •   Amazon S3 buckets
    •   flickr photos
    •   blog posts
    •   twitters
    •   (Nearly) everything else on the internet
Resources

•   Things
•   With names
•   That often relate to other things
•   On the internet
Representations

•   Formats
    • HTML, XML, JSON, JPG, SVG, etc.

•   Content Types (MIME Types)
    • text/html, application/xml, etc.
State


•   Resource state, not application state
•   Often database backed (CRUD)
Transfer
•   Use HTTP Verbs
    • (Constraints are liberating)

•   Design a Uniform Interface
    • Simple, Visible, Reusable

•   Stateless
•   Manipulate resources by transferring
    representations
Transfer
RESTless               RESTful
VERB   HREF            VERB   URI
POST   /users/create   POST   /users

GET    /users/1        GET    /users/1

POST   /users/1/update PUT    /users/1

????   /users/1/delete DELETE /users/1
Make Rails RESTful

• Design your Resources
• Create their Representations
• Expose them
• Profit!
Design Your Resources
 •   Identify your resources
 •   Design a URI scheme

     Entity    URI
     User      /users/quentin

     Photo     /photos/grand-canyon

     Comment   /photos/grand-canyon/comments/1


 •   In rails: map.resources
map.resources
  maps URIs to controllers
 maps HTTP verbs to actions
    map.resources :users
Resource   Verb     Action
/users     GET      index
/users     POST     create
/users/1   GET      show
/users/1   PUT      update
/users/1   DELETE   destroy
Design Your Resources
              Caveat Implementor


HTML and XHTML currently only support two HTTP verbs:
GET and POST. In order to get around this limitation, Rails
uses overloaded POST requests with a _method parameter
to simulate PUT and DELETE requests. Rails handles this
transparently through its view helpers and resource routing.
Create Representations
  Which formats will you provide?


 • User      • Photo     • Comment
  • HTML      • HTML      • XML
  • XML       • XML       • JSON
  • JSON      • JPG
  • vCard?    • Sizes?
Expose Resources
•   Determine the requested resource
•   Determine the requested representation
•   Manipulate the resource’s state based
    on the request method and parameters
•   Deliver an acceptable representation of
    the resource’s (new) state
Expose Resources
Determine the requested resource

•   Resources are identified by URIs
    • “Uniform Resource Indicator”

•   Rails maps URIs to controllers and
    actions
    • map.resources :users
Expose Resources
Determine the requested representation



 •   “Accept” header
 •   params[:format]
     • users/1.xml
Expose Resources
Manipulate the resource’s state (Rails 101)
   • Create the resource
    @user = User.new(params[:user])
    @user.save

   • Retrieve the resource
    @user = User.find(params[:id])

   • Update the resource
    @user.update_attributes(params[:user])

   • Delete the resource
    @user.destroy
Expose Resources
       Deliver a representation

• Based on Accept header
  def index
    @users = User.find(:all)

    respond_to do   |format|
      format.html   # text/html, application/xhtml+xml
      format.xml    # application/xml
      format.js     # text/javascript
    end
  end
Expose Resources
       Deliver a representation

• Based on format
  def index
    @users = User.find(:all)

    respond_to do   |format|
      format.html   # index
      format.xml    # index.xml
      format.js     # index.js
    end
  end
Expose Resources
       Deliver a representation

• Using templates
  def index
    @users = User.find(:all)

    respond_to do   |format|
      format.html   # index.html.erb
      format.xml    # index.xml.builder or index.xml.erb
      format.js     # index.js.rjs or index.js.erb
    end
  end
Expose Resources
       Deliver a representation

• Using coercion
  def index
    @users = User.find(:all)

    respond_to do |format|
      format.html # N/A
      format.xml { render :xml => @users.to_xml }
      format.js { render :text => @users.to_json }
    end
  end
Expose Resources
         Deliver a representation


•   Using Rails scaffold generator*
    • ruby script/generate scaffold User
    • Creates CRUD and index actions that map
      resources to an ActiveRecord model and
      respond to html and xml




       * edge rails / Rails 2.0 (scaffold_resource in 1.2.x)
Eating RESTfully


•   ActiveResource
•   Alternatives
Eating RESTfully
             ActiveResource

•   Designed to consume RESTful web
    services via XML
•   Treats resources as models
•   Fairly strict about resource architecture
•   Some examples please?
Eating RESTfully
                 ActiveResource
•   Consuming our users
    class User < ActiveResource::Base
      self.site = quot;http://www.example.comquot;
    end
    >> User.find(:all) # users.xml
    >> User.find(1) # users/1.xml


•   Consuming our photos
    class Photo < ActiveResource::Base
      self.site = quot;http://www.example.comquot;
    end
Eating RESTfully
           Alternatives



• rest-open-uri
• JQuery.getJSON()
Eating RESTfully
gem install rest-open-uri

•   Wraps Bare metal Net::HTTP library
•   Extends open-uri to allow PUT, POST,
    and DELETE
•   Some examples please?
    • http://pastie.caboo.se/117513
Eating RESTfully
         JQuery.getJSON()

•   Asynchronous HTTP request for text/
    javascript

•   JSON object can be passed to
    anonymous function
•   Some examples please?
Eating RESTfully
                    JQuery.getJSON()
var flickr_cats_uri = quot;http://api.flickr.com/services/feeds/photos_public.gne?
tags=cat&tagmode=any&format=json&jsoncallback=?quot;


$.getJSON(flickr_cats_uri, function(data){
  $.each(data.items, function(i,item){
    $(quot;<img/>quot;).attr(quot;srcquot;, item.media.m).appendTo(quot;#imagesquot;);
    if ( i == 3 ) return false;
  });
});
RESTful Tips & Tricks

•   DRY ActiveResource
•   DRY RESTful Controllers
•   Turn verbs into nouns
•   Custom MIME types
RESTful Tips
             DRY ActiveResource


•   Consuming our users
    class User < ActiveResource::Base
      self.site = quot;http://www.example.comquot;
    end


•   Consuming our photos
    class Photo < ActiveResource::Base
      self.site = quot;http://www.example.comquot;
    end
RESTful Tips
             DRY ActiveResource


•   Create a base class
    class ExampleSite < ActiveResource::Base
      self.site = quot;http://www.example.comquot;
    end


•   Consuming our users and photos
    class User < ExampleSite; end
    class Photo < ExampleSite; end
RESTful Tips
            DRY RESTful Controllers



•   resource_controller plugin
    class PostsController < ResourceController::Base
    end
    http://jamesgolick.com/resource_controller/rdoc/index.html
RESTful Tips
               Turn Verbs into Nouns
Replace RPC* style overloaded POST interfaces with resources that
  respond to a Uniform Interface by using standard HTTP verbs


 Method                          Overloaded POST
 User.find(1).activated?         GET users/1?q=activated

 User.find(1).activate!          POST users/1?m=activate

 User.find(1).deactivate! POST users/1?m=deactivate


                      * Remote Procedure Call
RESTful Tips
               Turn Verbs into Nouns
Replace RPC* style overloaded POST interfaces with resources that
  respond to a Uniform Interface by using standard HTTP verbs


 Method                          Uniform Interface
 User.find(1).activated?         GET users/1/activation

 User.find(1).activate!          POST users/1/activation

 User.find(1).deactivate! DELETE users/1/activation


                      * Remote Procedure Call
RESTful Tips
          Custom MIME Types


Mime::Type.register quot;image/pngquot;, :png
Mime::Type.register quot;text/x-vcardquot;, :vcard
RESTful Resources
RESTful Web
  Services
 http://www.oreilly.com/
catalog/9780596529260/
Peepcode:
 REST Basics
    http://nubyonrails.com/
articles/peepcode-rest-basics
Fielding
Dissertation:
 Chapter 5
  http://www.ics.uci.edu/
~fielding/pubs/dissertation/
    rest_arch_style.htm
These Slides
http://reinh.com/2007/11/13/
           rest-rails
“My God, it’s full of resources!”

More Related Content

What's hot

RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
Scott Leberknight
 
Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL designhiq5
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
Sumy PHP User Grpoup
 
Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010
Plataformatec
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsanthony_putignano
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
reneechemel
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
b0ris_1
 
Dethroning Grunt: Simple and Effective Builds with gulp.js
Dethroning Grunt: Simple and Effective Builds with gulp.jsDethroning Grunt: Simple and Effective Builds with gulp.js
Dethroning Grunt: Simple and Effective Builds with gulp.js
Jay Harris
 
Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014
Brian Cavalier
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
Taylor Lovett
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
Nicolas Ledez
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
Anand kalla
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Nguyen Duc Phu
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
Carol McDonald
 

What's hot (18)

RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL design
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIs
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
AJAX - An introduction
AJAX - An introductionAJAX - An introduction
AJAX - An introduction
 
Dethroning Grunt: Simple and Effective Builds with gulp.js
Dethroning Grunt: Simple and Effective Builds with gulp.jsDethroning Grunt: Simple and Effective Builds with gulp.js
Dethroning Grunt: Simple and Effective Builds with gulp.js
 
Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 

Viewers also liked

Keresztseg
KeresztsegKeresztseg
Keresztseg
Bőjte Mihály
 
sõnad
sõnadsõnad
sõnad
katal1
 
Tiempos y ángulos
Tiempos y ángulosTiempos y ángulos
Tiempos y ángulos
Bautista Valdés Menéndez
 
Plan De Trabajo Por Competencias
Plan De  Trabajo Por  CompetenciasPlan De  Trabajo Por  Competencias
Plan De Trabajo Por Competenciasnerysilva
 
Ghiciti Contextul!
Ghiciti Contextul!Ghiciti Contextul!
Ghiciti Contextul!
bordeanu.anca
 
Liitsona4kl
Liitsona4klLiitsona4kl
Liitsona4klmarytt
 
Fotografii Ramase In Istorie
Fotografii Ramase In IstorieFotografii Ramase In Istorie
Fotografii Ramase In Istoriebordeanu.anca
 
R Osszefoglalo
R OsszefoglaloR Osszefoglalo
R Osszefoglalo
Bőjte Mihály
 
TIGERS
TIGERSTIGERS
TIGERS
Andre Kaasik
 
Efficient Software Development with Visual Studio Team System 2008
Efficient Software Development with Visual Studio Team System 2008Efficient Software Development with Visual Studio Team System 2008
Efficient Software Development with Visual Studio Team System 2008
richardbushnell
 
U5 T1 Nereyda Mayra David
U5  T1  Nereyda Mayra DavidU5  T1  Nereyda Mayra David
U5 T1 Nereyda Mayra Davidnerysilva
 
Miroshnik Lv School8
Miroshnik Lv School8Miroshnik Lv School8
Miroshnik Lv School8
Lubamir
 
Convegno Cts Europa
Convegno Cts EuropaConvegno Cts Europa
Convegno Cts Europa
ctseuropa
 

Viewers also liked (14)

Keresztseg
KeresztsegKeresztseg
Keresztseg
 
sõnad
sõnadsõnad
sõnad
 
Tiempos y ángulos
Tiempos y ángulosTiempos y ángulos
Tiempos y ángulos
 
Plan De Trabajo Por Competencias
Plan De  Trabajo Por  CompetenciasPlan De  Trabajo Por  Competencias
Plan De Trabajo Por Competencias
 
Ghiciti Contextul!
Ghiciti Contextul!Ghiciti Contextul!
Ghiciti Contextul!
 
Liitsona4kl
Liitsona4klLiitsona4kl
Liitsona4kl
 
Fotografii Ramase In Istorie
Fotografii Ramase In IstorieFotografii Ramase In Istorie
Fotografii Ramase In Istorie
 
R Osszefoglalo
R OsszefoglaloR Osszefoglalo
R Osszefoglalo
 
TIGERS
TIGERSTIGERS
TIGERS
 
U4 T2 A B P
U4  T2  A B PU4  T2  A B P
U4 T2 A B P
 
Efficient Software Development with Visual Studio Team System 2008
Efficient Software Development with Visual Studio Team System 2008Efficient Software Development with Visual Studio Team System 2008
Efficient Software Development with Visual Studio Team System 2008
 
U5 T1 Nereyda Mayra David
U5  T1  Nereyda Mayra DavidU5  T1  Nereyda Mayra David
U5 T1 Nereyda Mayra David
 
Miroshnik Lv School8
Miroshnik Lv School8Miroshnik Lv School8
Miroshnik Lv School8
 
Convegno Cts Europa
Convegno Cts EuropaConvegno Cts Europa
Convegno Cts Europa
 

Similar to Rest And Rails

Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
Sagara Gunathunga
 
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
GeeksLab Odessa
 
Andrei shakirin rest_cxf
Andrei shakirin rest_cxfAndrei shakirin rest_cxf
Andrei shakirin rest_cxf
Aravindharamanan S
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routingTakeshi AKIMA
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
Viget Labs
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
Ben Scofield
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
Kong King
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
Arun Gupta
 
RailsスタイルからRESTを学ぼう よちがや.rb
RailsスタイルからRESTを学ぼう よちがや.rbRailsスタイルからRESTを学ぼう よちがや.rb
RailsスタイルからRESTを学ぼう よちがや.rb
Toru Kawamura
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
Samantha Geitz
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
Android and REST
Android and RESTAndroid and REST
Android and REST
Roman Woźniak
 
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.jsCarol McDonald
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
digitalsonic
 
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
Joshua Long
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
Aaron Stannard
 

Similar to Rest And Rails (20)

Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
WebCamp: Developer Day: Архитектура Web-приложений: обзор современных решений...
 
Andrei shakirin rest_cxf
Andrei shakirin rest_cxfAndrei shakirin rest_cxf
Andrei shakirin rest_cxf
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
 
RailsスタイルからRESTを学ぼう よちがや.rb
RailsスタイルからRESTを学ぼう よちがや.rbRailsスタイルからRESTを学ぼう よちがや.rb
RailsスタイルからRESTを学ぼう よちがや.rb
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
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
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
 
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
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 

Recently uploaded

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 

Recently uploaded (20)

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 

Rest And Rails

  • 1. REST & Rails Web Services for the Rails World Rein Henrichs http://reinh.com
  • 3. REST & Rails • What Is REST? • Make Rails RESTful • Eating RESTfully • RESTful Tips & Tricks • RESTful Resources
  • 5. Resources • Sources of specific information • Identified by a global identifier (URI) • Hyperlinked to other resources • Examples: • del.icio.us tags, links • Amazon S3 buckets • flickr photos • blog posts • twitters • (Nearly) everything else on the internet
  • 6. Resources • Things • With names • That often relate to other things • On the internet
  • 7. Representations • Formats • HTML, XML, JSON, JPG, SVG, etc. • Content Types (MIME Types) • text/html, application/xml, etc.
  • 8. State • Resource state, not application state • Often database backed (CRUD)
  • 9. Transfer • Use HTTP Verbs • (Constraints are liberating) • Design a Uniform Interface • Simple, Visible, Reusable • Stateless • Manipulate resources by transferring representations
  • 10. Transfer RESTless RESTful VERB HREF VERB URI POST /users/create POST /users GET /users/1 GET /users/1 POST /users/1/update PUT /users/1 ???? /users/1/delete DELETE /users/1
  • 11. Make Rails RESTful • Design your Resources • Create their Representations • Expose them • Profit!
  • 12. Design Your Resources • Identify your resources • Design a URI scheme Entity URI User /users/quentin Photo /photos/grand-canyon Comment /photos/grand-canyon/comments/1 • In rails: map.resources
  • 13. map.resources maps URIs to controllers maps HTTP verbs to actions map.resources :users Resource Verb Action /users GET index /users POST create /users/1 GET show /users/1 PUT update /users/1 DELETE destroy
  • 14. Design Your Resources Caveat Implementor HTML and XHTML currently only support two HTTP verbs: GET and POST. In order to get around this limitation, Rails uses overloaded POST requests with a _method parameter to simulate PUT and DELETE requests. Rails handles this transparently through its view helpers and resource routing.
  • 15. Create Representations Which formats will you provide? • User • Photo • Comment • HTML • HTML • XML • XML • XML • JSON • JSON • JPG • vCard? • Sizes?
  • 16. Expose Resources • Determine the requested resource • Determine the requested representation • Manipulate the resource’s state based on the request method and parameters • Deliver an acceptable representation of the resource’s (new) state
  • 17. Expose Resources Determine the requested resource • Resources are identified by URIs • “Uniform Resource Indicator” • Rails maps URIs to controllers and actions • map.resources :users
  • 18. Expose Resources Determine the requested representation • “Accept” header • params[:format] • users/1.xml
  • 19. Expose Resources Manipulate the resource’s state (Rails 101) • Create the resource @user = User.new(params[:user]) @user.save • Retrieve the resource @user = User.find(params[:id]) • Update the resource @user.update_attributes(params[:user]) • Delete the resource @user.destroy
  • 20. Expose Resources Deliver a representation • Based on Accept header def index @users = User.find(:all) respond_to do |format| format.html # text/html, application/xhtml+xml format.xml # application/xml format.js # text/javascript end end
  • 21. Expose Resources Deliver a representation • Based on format def index @users = User.find(:all) respond_to do |format| format.html # index format.xml # index.xml format.js # index.js end end
  • 22. Expose Resources Deliver a representation • Using templates def index @users = User.find(:all) respond_to do |format| format.html # index.html.erb format.xml # index.xml.builder or index.xml.erb format.js # index.js.rjs or index.js.erb end end
  • 23. Expose Resources Deliver a representation • Using coercion def index @users = User.find(:all) respond_to do |format| format.html # N/A format.xml { render :xml => @users.to_xml } format.js { render :text => @users.to_json } end end
  • 24. Expose Resources Deliver a representation • Using Rails scaffold generator* • ruby script/generate scaffold User • Creates CRUD and index actions that map resources to an ActiveRecord model and respond to html and xml * edge rails / Rails 2.0 (scaffold_resource in 1.2.x)
  • 25. Eating RESTfully • ActiveResource • Alternatives
  • 26. Eating RESTfully ActiveResource • Designed to consume RESTful web services via XML • Treats resources as models • Fairly strict about resource architecture • Some examples please?
  • 27. Eating RESTfully ActiveResource • Consuming our users class User < ActiveResource::Base self.site = quot;http://www.example.comquot; end >> User.find(:all) # users.xml >> User.find(1) # users/1.xml • Consuming our photos class Photo < ActiveResource::Base self.site = quot;http://www.example.comquot; end
  • 28. Eating RESTfully Alternatives • rest-open-uri • JQuery.getJSON()
  • 29. Eating RESTfully gem install rest-open-uri • Wraps Bare metal Net::HTTP library • Extends open-uri to allow PUT, POST, and DELETE • Some examples please? • http://pastie.caboo.se/117513
  • 30. Eating RESTfully JQuery.getJSON() • Asynchronous HTTP request for text/ javascript • JSON object can be passed to anonymous function • Some examples please?
  • 31. Eating RESTfully JQuery.getJSON() var flickr_cats_uri = quot;http://api.flickr.com/services/feeds/photos_public.gne? tags=cat&tagmode=any&format=json&jsoncallback=?quot; $.getJSON(flickr_cats_uri, function(data){ $.each(data.items, function(i,item){ $(quot;<img/>quot;).attr(quot;srcquot;, item.media.m).appendTo(quot;#imagesquot;); if ( i == 3 ) return false; }); });
  • 32. RESTful Tips & Tricks • DRY ActiveResource • DRY RESTful Controllers • Turn verbs into nouns • Custom MIME types
  • 33. RESTful Tips DRY ActiveResource • Consuming our users class User < ActiveResource::Base self.site = quot;http://www.example.comquot; end • Consuming our photos class Photo < ActiveResource::Base self.site = quot;http://www.example.comquot; end
  • 34. RESTful Tips DRY ActiveResource • Create a base class class ExampleSite < ActiveResource::Base self.site = quot;http://www.example.comquot; end • Consuming our users and photos class User < ExampleSite; end class Photo < ExampleSite; end
  • 35. RESTful Tips DRY RESTful Controllers • resource_controller plugin class PostsController < ResourceController::Base end http://jamesgolick.com/resource_controller/rdoc/index.html
  • 36. RESTful Tips Turn Verbs into Nouns Replace RPC* style overloaded POST interfaces with resources that respond to a Uniform Interface by using standard HTTP verbs Method Overloaded POST User.find(1).activated? GET users/1?q=activated User.find(1).activate! POST users/1?m=activate User.find(1).deactivate! POST users/1?m=deactivate * Remote Procedure Call
  • 37. RESTful Tips Turn Verbs into Nouns Replace RPC* style overloaded POST interfaces with resources that respond to a Uniform Interface by using standard HTTP verbs Method Uniform Interface User.find(1).activated? GET users/1/activation User.find(1).activate! POST users/1/activation User.find(1).deactivate! DELETE users/1/activation * Remote Procedure Call
  • 38. RESTful Tips Custom MIME Types Mime::Type.register quot;image/pngquot;, :png Mime::Type.register quot;text/x-vcardquot;, :vcard
  • 40. RESTful Web Services http://www.oreilly.com/ catalog/9780596529260/
  • 41. Peepcode: REST Basics http://nubyonrails.com/ articles/peepcode-rest-basics
  • 42. Fielding Dissertation: Chapter 5 http://www.ics.uci.edu/ ~fielding/pubs/dissertation/ rest_arch_style.htm
  • 44. “My God, it’s full of resources!”