SlideShare a Scribd company logo
1 of 42
RESTful APIs




      giancarlo valente - @gncvalente
l’idea e’ semplice:

usare il protocollo che fa’ “muovere” il web
per realizzare l’architettura a servizi di un sistema complesso
l’idea e’ semplice:

usare il protocollo che fa’ “muovere” il web
per realizzare l’architettura a servizi di un sistema complesso

ed ereditarne i vantaggi
TANTE IMPLEMENTAZIONI
         DI ARCHITETTURE
        A SERVIZI DISTRIBUITI
DCOM

CORBA

WS_*

HTTP-RPC

...
WWW
         il web e' un insieme di servizi (APIs),
   utilizzabili dagli uomini, attraverso un browser


                    esempio:
      http://www.google.com/search?q=puglia


un insieme di regole prefissate consente di usufruire
     di n-milioni di servizi in modo trasparente
il web e' l'API distribuita di maggior successo

                   perche'?
HTTP
                                DOCUMENT BASED
                                  PROTOCOL
          il client mette un documento in un 'envelope'
                       e lo spedisce al server

   il server risponde con un'altro documento in un 'enevlope'

 l'HTTP definisce in modo dettagliato come deve essere la busta,
ma e' completamente libero sul formato del documento contenuto
METHOD INFORMATION
SCOPING INFORMATION
     cosa devo fare, e su cosa




                             Per Classificare le varie
                             tipologie di servizi
METHOD INFORMATION
SCOPING INFORMATION
       cosa devo fare, e su cosa

                WS* -
    Method information ==> body
    Scoping information ==> body
          es. AddItem(cartId)
METHOD INFORMATION
 SCOPING INFORMATION
                  cosa devo fare, e su cosa

                          WS* -
              Method information ==> body
              Scoping information ==> body
                    es. AddItem(cartId)

                  HTTP-Rpc protocls
                Method information ==> url
               Scoping information ==> body
/carrello.php?op=AggiungiProdotto (body:CarrelloID ProdottoID)
METHOD INFORMATION
 SCOPING INFORMATION

                        REST
          Method information ==> HTTP verb
            Scoping information ==> URI *

es. POST http://www.mioecommerce.it/carrello/34Abc9/prodotti
             body: { Prodotto: 5467, Quantita’: 2}

               *(unique resource identifier)
DIFFERENZA
                     in REST ragiono per nomi
                       (invece che per verbi)

          i verbi sono fissi : GET, PUT, POST, DELETE ...

            dare un nome alle risorse e’ il mio lavoro



                              Resource Oriented
Operation Oriented
                              /posts   (GET, POST)
- CreateBlogPost
                              /post/{id}    (GET, PUT, DELETE)
- GetBlogPostByTag
                              /tags/{a}/posts    (GET)
- GetBlogPostByAuthor
                              /authors/{a}/posts (GET)
ESEMPIO
devo aggiungere un prodotto al carrello
          POST /cart/{cartId}
           Body: prodotto

    devo creare una nuova sessione
            POST /sessions

devo associare uno studente a una classe
PUT /classes/Math101/students/Giancarlo
RESOURCE ORIENTED
        ARCHITECTURES


ROA is a way of turning a problem into a RESTful web service:
   an arrangement of URIs, HTTP verbs, xml, json, html ...
PRINCIPI: ADRESSABILITY
           URI (adressability principle)


           naming things as resources
 every resouce is identified by a unique identifier
PRINCIPI: REPRESENTATION
    Rappresentazioni (representation oriented)


 la comunicazione avviene tramite rappresentazioni
PRINCIPI: UNIFORMINTERFACE
HTTP method (uniform interface principle)



     GET                  SAFE                IDEMPOTENT


    PUT                 NOT SAFE              IDEMPOTENT


    POST                NOT SAFE            NOT IDEMPOTENT


  DELETE                NOT SAFE              IDEMPOTENT
PRINCIPI: STATELESS
 Stateless (stateless communication)
FRAMEWORKS PER
 REALIZZARE UN
  REST SERVICE?
 Ruby ---> webmachine, sinatra

     node.js ---> connect

        C# --> nancy
WEBMACHINE
Erlang toolkit ... build full featured HTTP services

        progetto finale, mini blog engine,
            completamente restful
RESTFUL BLOG

/posts         GET, POST   html, json json
RESTFUL BLOG

/posts                 GET, POST     html, json json

/post/{permalink}   GET, PUT, DELETE html, json json
RESTFUL BLOG

/posts                 GET, POST     html, json json

/post/{permalink}   GET, PUT, DELETE html, json json

/tags                     GET        html, json
RESTFUL BLOG

/posts                 GET, POST     html, json json

/post/{permalink}   GET, PUT, DELETE html, json json

/tags                     GET        html, json

/tags/{tag}/posts         GET        html, json
RESTFUL BLOG

/posts                 GET, POST     html, json json

/post/{permalink}   GET, PUT, DELETE html, json json

/tags                     GET        html, json

/tags/{tag}/posts         GET        html, json

/authors                  GET        html, json
faccio vedere subito il

               RESTFUL BLOG                          risualtato finale

                                                     dalle risorse piu’ semplici
                                                     al blog
                                                     e etag
                      il codice erlang ...

                      parto dal JS della pagina
                      statica
/posts                            GET, POST       html, json json
                      e vado poi di risorsa in
                      risorsa seguendo le slide
/post/{permalink}          GET, PUT, DELETE html, json json
                      seguenti



/tags                                    GET      html, json

/tags/{tag}/posts                        GET      html, json

/authors                                 GET      html, json

/authors/{author}/posts                  GET      html, json
demo:

               simple resource

               git checkout “tag” v1

               fa’ output di un testo




HTTP E’ SOLO TESTO
CODICE

                   demo:

                   rappresentazioni
                   json e html        demo:

                   /posts             cambio titolo del post
demo:                                 e comunico un permanent
                   /post/x
                                      redirect
/posts POST, GET                      demo col browser
con client HTTP    git checkout v4
                                      git checkout v5
git checkout v3
RISORSA SEMPLICE
invia in output la configurazione di input
RISORSA CON TEMPLATE
    home page del blog, da template.
RAPPRESENTAZONI
risorsa con rappresentazioni in JSON e HTML
ACCEPT: JSON
risorsa che accetta in ingresso JSON
MATURITY LEVEL 3
le risorse includono dei link, per indirizzare il client, verso la URI
             della risorsa stessa, o verso sottorisorse




                                                     demo:

                                                     altre risorse, e links

                                                     git checkout v6
MATURITY LEVEL 3
le risorse includono dei link, per indirizzare il client, verso la URI
             della risorsa stessa, o verso sottorisorse




                                                       demo:

                                                       altre risorse, e links

                                                       git checkout v6
demo

                                        demo col browser

                                        git checkout v7




GET CONDIZIONALE
                  etag
  it is not caching, it is much more!
GET CONDIZIONALE
           etag
     with webmachine
MOVED PERMANENTLY
   il titolo del blogpost e’ cambiato
            il permalink cambia
IL BLOG
RESTful API, HTML, CSS ... e un po’ di JS (pjax)




                              demo:

                              git checkout v8

                              verifica che etag
                              funziona ancora!
                              anche col blog.
demo:

                                                Amazon Cloud Front




                       ALTRO ?
cache control, layers, index dell’api, cdn, web cache, application
                    firewall, reverse proxy ...
CONTATTI
Agile Coach, Giancarlo Valente

    twitter: @gncvalente

   www.giancarlovalente.it
ENJOY AND HAVE FUN
 Learn some functional programming language
          Clojure, Haskell, Erlang ...
          the hacker that you save,
                could be you!



       Agile Coach, Giancarlo Valente

            twitter: @gncvalente

          www.giancarlovalente.it

More Related Content

Similar to RESTful APIs (ITA) - /w WebMachine

Similar to RESTful APIs (ITA) - /w WebMachine (20)

Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5
 
Lamp Ld2008
Lamp Ld2008Lamp Ld2008
Lamp Ld2008
 
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
Progettazione e sviluppo di applicazioni web 2.0 con PHP e AjaxProgettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
 
Sviluppare un plugin WordPress da zero - WordCamp Bologna 2018
Sviluppare un plugin WordPress da zero - WordCamp Bologna 2018Sviluppare un plugin WordPress da zero - WordCamp Bologna 2018
Sviluppare un plugin WordPress da zero - WordCamp Bologna 2018
 
WebSphere Portal e WCM #dd12
WebSphere Portal e WCM #dd12WebSphere Portal e WCM #dd12
WebSphere Portal e WCM #dd12
 
WebSphere Portal & User Experience
WebSphere Portal & User ExperienceWebSphere Portal & User Experience
WebSphere Portal & User Experience
 
IBM WCM e SEO
IBM WCM e SEOIBM WCM e SEO
IBM WCM e SEO
 
Novità di Asp.Net 4.0
Novità di Asp.Net 4.0Novità di Asp.Net 4.0
Novità di Asp.Net 4.0
 
Drupal diventa un CMF e WordPress che fa? Slide WordCamp Milano 2019
Drupal diventa un CMF e WordPress che fa? Slide WordCamp Milano 2019Drupal diventa un CMF e WordPress che fa? Slide WordCamp Milano 2019
Drupal diventa un CMF e WordPress che fa? Slide WordCamp Milano 2019
 
Corso di php01
Corso di php01Corso di php01
Corso di php01
 
Programming iOS lezione 4
Programming iOS lezione 4Programming iOS lezione 4
Programming iOS lezione 4
 
Introduzione a node.js
Introduzione a node.jsIntroduzione a node.js
Introduzione a node.js
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.js
 
Integrazione con Visual Studio Online
Integrazione con Visual Studio OnlineIntegrazione con Visual Studio Online
Integrazione con Visual Studio Online
 
04 Tapestry5 In Action Pratica
04   Tapestry5 In Action   Pratica04   Tapestry5 In Action   Pratica
04 Tapestry5 In Action Pratica
 
react-it.pdf
react-it.pdfreact-it.pdf
react-it.pdf
 
Yagwto
YagwtoYagwto
Yagwto
 
Html5 e PHP
Html5 e PHPHtml5 e PHP
Html5 e PHP
 
6.01 php ajax_json_mysql
6.01 php ajax_json_mysql6.01 php ajax_json_mysql
6.01 php ajax_json_mysql
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
 

RESTful APIs (ITA) - /w WebMachine

  • 1. RESTful APIs giancarlo valente - @gncvalente
  • 2. l’idea e’ semplice: usare il protocollo che fa’ “muovere” il web per realizzare l’architettura a servizi di un sistema complesso
  • 3. l’idea e’ semplice: usare il protocollo che fa’ “muovere” il web per realizzare l’architettura a servizi di un sistema complesso ed ereditarne i vantaggi
  • 4. TANTE IMPLEMENTAZIONI DI ARCHITETTURE A SERVIZI DISTRIBUITI DCOM CORBA WS_* HTTP-RPC ...
  • 5. WWW il web e' un insieme di servizi (APIs), utilizzabili dagli uomini, attraverso un browser esempio: http://www.google.com/search?q=puglia un insieme di regole prefissate consente di usufruire di n-milioni di servizi in modo trasparente
  • 6. il web e' l'API distribuita di maggior successo perche'?
  • 7. HTTP DOCUMENT BASED PROTOCOL il client mette un documento in un 'envelope' e lo spedisce al server il server risponde con un'altro documento in un 'enevlope' l'HTTP definisce in modo dettagliato come deve essere la busta, ma e' completamente libero sul formato del documento contenuto
  • 8. METHOD INFORMATION SCOPING INFORMATION cosa devo fare, e su cosa Per Classificare le varie tipologie di servizi
  • 9. METHOD INFORMATION SCOPING INFORMATION cosa devo fare, e su cosa WS* - Method information ==> body Scoping information ==> body es. AddItem(cartId)
  • 10. METHOD INFORMATION SCOPING INFORMATION cosa devo fare, e su cosa WS* - Method information ==> body Scoping information ==> body es. AddItem(cartId) HTTP-Rpc protocls Method information ==> url Scoping information ==> body /carrello.php?op=AggiungiProdotto (body:CarrelloID ProdottoID)
  • 11. METHOD INFORMATION SCOPING INFORMATION REST Method information ==> HTTP verb Scoping information ==> URI * es. POST http://www.mioecommerce.it/carrello/34Abc9/prodotti body: { Prodotto: 5467, Quantita’: 2} *(unique resource identifier)
  • 12. DIFFERENZA in REST ragiono per nomi (invece che per verbi) i verbi sono fissi : GET, PUT, POST, DELETE ... dare un nome alle risorse e’ il mio lavoro Resource Oriented Operation Oriented /posts (GET, POST) - CreateBlogPost /post/{id} (GET, PUT, DELETE) - GetBlogPostByTag /tags/{a}/posts (GET) - GetBlogPostByAuthor /authors/{a}/posts (GET)
  • 13. ESEMPIO devo aggiungere un prodotto al carrello POST /cart/{cartId} Body: prodotto devo creare una nuova sessione POST /sessions devo associare uno studente a una classe PUT /classes/Math101/students/Giancarlo
  • 14. RESOURCE ORIENTED ARCHITECTURES ROA is a way of turning a problem into a RESTful web service: an arrangement of URIs, HTTP verbs, xml, json, html ...
  • 15. PRINCIPI: ADRESSABILITY URI (adressability principle) naming things as resources every resouce is identified by a unique identifier
  • 16. PRINCIPI: REPRESENTATION Rappresentazioni (representation oriented) la comunicazione avviene tramite rappresentazioni
  • 17. PRINCIPI: UNIFORMINTERFACE HTTP method (uniform interface principle) GET SAFE IDEMPOTENT PUT NOT SAFE IDEMPOTENT POST NOT SAFE NOT IDEMPOTENT DELETE NOT SAFE IDEMPOTENT
  • 18. PRINCIPI: STATELESS Stateless (stateless communication)
  • 19. FRAMEWORKS PER REALIZZARE UN REST SERVICE? Ruby ---> webmachine, sinatra node.js ---> connect C# --> nancy
  • 20. WEBMACHINE Erlang toolkit ... build full featured HTTP services progetto finale, mini blog engine, completamente restful
  • 21. RESTFUL BLOG /posts GET, POST html, json json
  • 22. RESTFUL BLOG /posts GET, POST html, json json /post/{permalink} GET, PUT, DELETE html, json json
  • 23. RESTFUL BLOG /posts GET, POST html, json json /post/{permalink} GET, PUT, DELETE html, json json /tags GET html, json
  • 24. RESTFUL BLOG /posts GET, POST html, json json /post/{permalink} GET, PUT, DELETE html, json json /tags GET html, json /tags/{tag}/posts GET html, json
  • 25. RESTFUL BLOG /posts GET, POST html, json json /post/{permalink} GET, PUT, DELETE html, json json /tags GET html, json /tags/{tag}/posts GET html, json /authors GET html, json
  • 26. faccio vedere subito il RESTFUL BLOG risualtato finale dalle risorse piu’ semplici al blog e etag il codice erlang ... parto dal JS della pagina statica /posts GET, POST html, json json e vado poi di risorsa in risorsa seguendo le slide /post/{permalink} GET, PUT, DELETE html, json json seguenti /tags GET html, json /tags/{tag}/posts GET html, json /authors GET html, json /authors/{author}/posts GET html, json
  • 27. demo: simple resource git checkout “tag” v1 fa’ output di un testo HTTP E’ SOLO TESTO
  • 28. CODICE demo: rappresentazioni json e html demo: /posts cambio titolo del post demo: e comunico un permanent /post/x redirect /posts POST, GET demo col browser con client HTTP git checkout v4 git checkout v5 git checkout v3
  • 29. RISORSA SEMPLICE invia in output la configurazione di input
  • 30. RISORSA CON TEMPLATE home page del blog, da template.
  • 32. ACCEPT: JSON risorsa che accetta in ingresso JSON
  • 33. MATURITY LEVEL 3 le risorse includono dei link, per indirizzare il client, verso la URI della risorsa stessa, o verso sottorisorse demo: altre risorse, e links git checkout v6
  • 34. MATURITY LEVEL 3 le risorse includono dei link, per indirizzare il client, verso la URI della risorsa stessa, o verso sottorisorse demo: altre risorse, e links git checkout v6
  • 35. demo demo col browser git checkout v7 GET CONDIZIONALE etag it is not caching, it is much more!
  • 36. GET CONDIZIONALE etag with webmachine
  • 37. MOVED PERMANENTLY il titolo del blogpost e’ cambiato il permalink cambia
  • 38. IL BLOG RESTful API, HTML, CSS ... e un po’ di JS (pjax) demo: git checkout v8 verifica che etag funziona ancora! anche col blog.
  • 39. demo: Amazon Cloud Front ALTRO ? cache control, layers, index dell’api, cdn, web cache, application firewall, reverse proxy ...
  • 40. CONTATTI Agile Coach, Giancarlo Valente twitter: @gncvalente www.giancarlovalente.it
  • 41.
  • 42. ENJOY AND HAVE FUN Learn some functional programming language Clojure, Haskell, Erlang ... the hacker that you save, could be you! Agile Coach, Giancarlo Valente twitter: @gncvalente www.giancarlovalente.it

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n