SlideShare uma empresa Scribd logo
1 de 77
Baixar para ler offline
REST and
Resource Oriented
  Architectures
          Gabriele Lana
    gabriele.lana@gmail.com
what is
REST?
REST is not
           a Protocol
        an Architecture
           a Software
          a Standard
a fancy name for Web Services
          a Buzzword
Representational
                             State
                             Transfer

                                Roy T. Fielding
“Architectural Styles and the Design of Network-based Software Architectures”
                            Ph.D dissertation, 2000
REST is
     a Software Architecture Style
 a set of Constraints on Component
Interaction that, when obeyed, cause
  the resulting Architecture to have
          certain properties


Roy T. Fielding http://roy.gbiv.com/untangled/2008/on-software-architecture
?
prediction for 2009
 “Roy Fielding will officially disown most of the
     RESTful authors and software packages
available. Nobody will care, or worse, somebody
  looking to make a name for themselves will
  proclaim that “Roy doesn't really understand
     REST”, and they'll be right: Roy doesn't
  understand what they consider to be REST”


    http://dotnet.dzone.com/articles/ted-neward-2009-predictions-20
why?
“... the motivation for developing REST was to
create an architectural model for how the Web
  should work, such that it could serve as the
     guiding framework for the Web protocol
                   standards”




   http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm
no Silver Bullets
         REST vs
          SOA vs
         SOAP vs
          RPC vs
         WS-* vs
            ...
but sometimes
REST is better :-)
web applications
Information Flow
             RDB
HTTP
       OOP   MS
HTTP is REST

              RDB
HTTP
       OOP    MS
Impedance
        Mismatch
                   RDB
HTTP
         OOP       MS
Accidental
       Complexity
                    RDB
HTTP
          OOP       MS
Essential
       Complexity
                    RDB
HTTP
          OOP       MS
RDB
RPC    OOP    MS




HTTP
        RPC
Resource Oriented
  Architectures
              RDB
HTTP   ROA
              MS
maybe not today,
 but Yes, we Can
HTTP   ROA   DATA
REST by Example
   (Chess)
how to Design a
       RESTful service
         Step by Step

Leonard Richardson & Sam Ruby “RESTful Web Services”, O’Reilly 2007
1. every Resource
must be Identified
Pawn   Move   Bishop
Game Player
Rank
      Board Rook
           File
 Knight
     Position
    Queen   Square
every Concept in
your Domain can
  be a Resource
2. design the URIs
(Ubiquitous Language)
/position/wqd3,wkd1,bqd7,bkd8
/position/wqd3,wkd1,bqe6,bkf8/d3-d8
/move/wqd3,wkd1,bkf8-wqd8,wkd1,bkf8
/position/initial
/board/4815162342




/position/wqd3,wkd1,bqe6,bkf8


    move = d3-d8



/position/wqd8,wkd1,bqe6,bkf8
/player/50298
3. for each Resource
  expose a subset of
the Uniform Interface
Uniform Interface
    GET (Read)
   POST (Create)
   PUT (Update)
  DELETE (Delete)
GET /player/50298 HTTP/1.1



  Retrieve informations
  on identified Resource

      Idempotent,
   should not change
   the Resource State
POST /position/wqd3,wkd1,bke8 HTTP/1.1
n
move = d3-d8


HTTP/1.1 302 Found
Location: /position/wqd8,wkd1,bke8


         POST to let Resources
          process informations
POST /game HTTP/1.1
n
white = /player/50298 &
black = /player/39650


HTTP/1.1 201 Created
Location: /game/42


            POST to Create
             new Resources
PUT /board/4815162342 HTTP/1.1
n
position = /position/wqd3,wkd2,bke8


HTTP/1.1 205 Reset Content



           PUT to Update
         Resource Informations
PUT /position/wqd3,wkd1,bke8 HTTP/1.1
n
position = /position/wqd3,wkd2,bke8


HTTP/1.1 405 Method Not Allowed


           a Method can be
     not supported by a Resource
       but should not be ignored
DELETE /board/4815162342 HTTP/1.1


HTTP/1.1 204 No Content




              DELETE to
            logically Remove
                Resources
4. for each Resource
design Representations
  from and to Client
GET /position/wqd3,wkd2,bke8 HTTP/1.1
Accept: text/plain

HTTP/1.1 200 OK
Content-Type: text/plain;format=fen
n
3k4/8/3q4/8/8/8/8/5K2


   client/server Content Negotiation
           (MIME properties)
GET /position/wqd3,wkd2,bke8 HTTP/1.1
Accept: image/png;q=0.8, text/plain;q=0.2

HTTP/1.1 200 OK
Content-Type: image/png
n
PNG...


   client/server Content Negotiation
              (Preferences)
GET /position/wqd3,wkd2,bke8.png HTTP/1.1
Accept: image/png

HTTP/1.1 200 OK
Content-Type: image/png
n
PNG...


        client Explicit Request of
              Content-Type
GET /position/wqd3,wkd2,bke8.gif HTTP/1.1
Accept: image/gif

HTTP/1.1 406 Not Acceptable
             or more friendly
HTTP/1.1 300 Multiple Choices
Content-Type: application/xml
n
<choices><content type=”image/png” uri=”...”>
GET /game/42 HTTP/1.1
Accept: application/vnd.dharma.chess

<game>
 <player role=”white”>/player/1001</player>
 <player role=”black”>/player/1002</player>
 <moves>
   <position>/position/initial</position>
 </moves>
</game>


            custom Content-Type
wait...
  what about
   plain old
Web Applications?
GET /game/42 HTTP/1.1
Accept: application/xhtml+xml

<html>
 ... <a rel=”owner” href=”/player/1001”>...</a> ...
 <ul class=”moves”>
   <li><image src=”/position/initial.png”/></li>
 </ul>
</html>


       Semantic Web is not a dream
Tim Berners-Lee
 on Linked Data
“... almost 20 years ago I wanted
    to reframe the way we use
  informations ... I invented the
Word Wide Web ... now is time
       for a new reframing...”


         Tim Berners-Lee @ http://linkeddata.org
expected behavior of the web
1. Use URIs as names for things
2. Use HTTP URIs so that people
       can look up those names
3. When someone looks up a URI,
      provide useful information
4. Include links to other URIs, so
  that they can discover more things
POST /game/42 HTTP/1.1
Content-Type: application/vnd.dharma.chess

Authorization: Basic dXN1cm5hbWU6cG...
n
<game>
 <player>...</player>
 <moves>
   <position>/position/initial</position>

  <position color=”white”>
   /position/wra1,wna2,...,wpd4,...
  </position>
 </moves>
</game>



                 ... from and to the Client
5. design
typical flows
and
error
conditions
POST /game/42 HTTP/1.1
Content-Type: application/vnd.dharma.chess
Authorization: Basic dXN1...
n
<game>
 <player>...</player>
 <moves>
   <position>/position/initial</position>

  <position color=”white”>
   /position/wra1,wna2,...,wpd4,...
  </position>
 </moves>
</game>




            white Player make first move
HTTP/1.1 201 Created
Location: /game/42/position/2

      Response to the white Player
GET /game/42/position/2

HTTP/1.1 301 Moved Permanently
Location: /position/wra1,wna2,...,wpd4,...
GET /game/42 HTTP/1.1
Authorization: Basic dXN1...
n
<game>
 <player>...</player>
 <moves>...</player>
</game>



GET /game/42 HTTP/1.1
Authorization: Basic aYR5...
n
<game>
 <player>...</player>
 <moves>...</player>
</game>


                  both Players must GET
                 the game Representation
POST /game/42 HTTP/1.1
Content-Type: application/vnd.dharma.chess
Authorization: Basic aYR5...
n
<game>
 <player>...</player>
 <moves>
   <position>/position/initial</position>
   <position>/position/wra1,wna2,...,wpd4,...</position>

  <position color=”black”>
   /position/wra1,wna2,...,bpd5,...
  </position>
 </moves>
</game>



       black Player can make next move
POST /game/42 HTTP/1.1
Content-Type: application/vnd.dharma.chess
Authorization: Basic aYR5...
n
...




     what if black Player try to resend?
HTTP/1.1 409 Conflict

             the game Representation is
                    out of date
POST /game/42 HTTP/1.1
Content-Type: application/vnd.dharma.chess
Authorization: Basic aYR5...
n
...




what if black Player try to move again?
HTTP/1.1 403 Forbidden

           the black Player should wait
           for the white Player to move
POST /position/wqd3,wkd1,bke8 HTTP/1.1
n
move = d3-e8

what if we try to make a wrong move?
HTTP/1.1 404 Not Found

    Business Rules could be easily
  expressed through the Resource's
               Behavior
wait...
 what about
complex User
 Interfaces?
what about Gmail
what about Gmail
      JS
           HTTP




?     JS
what about Gmail
FAQ: cool URIs
      are RESTful?
                        OpenSocial
                     /people/{guid}/@all
Collection of all people connected to user {guid}
 http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/restful-protocol.html
FAQ: REST is
   stateless?
     Statelessness says that
all possible states of the server
       are also Resources
         (Resource State)
FAQ: REST is
   stateless?
     Statelessness says that
    each message contains
all the informations necessary
  to understand the Request
       (Application State)
Representational State Transfer




                           Application
                             State
             R3
                  R4
       R2
  R1

                  CLIENT




        SERVER
                       Resource
                        State
your application
can be Discoverable
your application
 can be Testable
Testability
View             Model



       Control




       HTTP
Testability
too much code untested

 View             Model



        Control




        HTTP
Testability
too fragile and unreliable

 View             Model



        Control




        HTTP
Testability
        Player
Board

           Position
   Game

          Move




                      Js
        HTTP
Testability
 what about the view?
        Player
Board

           Position
   Game

          Move




                      Js
        HTTP
your application
can be Composable
your application
 can be Scalable
...so what Really
 means (for me)
 being RESTful?
now the Web
can talk about
    chess
REST e Resource Oriented Architectures

Mais conteúdo relacionado

Semelhante a REST e Resource Oriented Architectures

Jordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-eraJordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-era
.toster
 
Communication Protocols And Web Services
Communication Protocols And Web ServicesCommunication Protocols And Web Services
Communication Protocols And Web Services
Omer Katz
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 
Hacking Client Side Insecurities
Hacking Client Side InsecuritiesHacking Client Side Insecurities
Hacking Client Side Insecurities
amiable_indian
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
Matthew Turland
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
Gaurav Bhardwaj
 

Semelhante a REST e Resource Oriented Architectures (20)

Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
 
There is REST and then there is "REST"
There is REST and then there is "REST"There is REST and then there is "REST"
There is REST and then there is "REST"
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Api Design and More (Friday Training at Itnig)
Api Design and More (Friday Training at Itnig)Api Design and More (Friday Training at Itnig)
Api Design and More (Friday Training at Itnig)
 
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
 
Jordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-eraJordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-era
 
Communication Protocols And Web Services
Communication Protocols And Web ServicesCommunication Protocols And Web Services
Communication Protocols And Web Services
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTP
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 
Hacking Client Side Insecurities
Hacking Client Side InsecuritiesHacking Client Side Insecurities
Hacking Client Side Insecurities
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
 
Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
 

Mais de GrUSP

PHP & IBM i
PHP & IBM iPHP & IBM i
PHP & IBM i
GrUSP
 
Memi Beltrame Collaborative Design
Memi Beltrame Collaborative DesignMemi Beltrame Collaborative Design
Memi Beltrame Collaborative Design
GrUSP
 

Mais de GrUSP (10)

Drupal come framework di sviluppo
Drupal come framework di sviluppoDrupal come framework di sviluppo
Drupal come framework di sviluppo
 
PayPal e PHP
PayPal e PHPPayPal e PHP
PayPal e PHP
 
Zend Server
Zend ServerZend Server
Zend Server
 
Zend Dojo
Zend DojoZend Dojo
Zend Dojo
 
PHP & IBM i
PHP & IBM iPHP & IBM i
PHP & IBM i
 
Programmazione Ad Eventi In Php
Programmazione Ad Eventi In PhpProgrammazione Ad Eventi In Php
Programmazione Ad Eventi In Php
 
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriJoomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
 
Memi Beltrame Collaborative Design
Memi Beltrame Collaborative DesignMemi Beltrame Collaborative Design
Memi Beltrame Collaborative Design
 
Mocking Objects Practices
Mocking Objects PracticesMocking Objects Practices
Mocking Objects Practices
 

Último

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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...
 
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
 

REST e Resource Oriented Architectures