Cos’è  REST ?
REST  non è un  Protocollo un’ Architettura un  Software uno  Standard un nome carino per  Web Services una  Buzzword
Re presentational S tate T ransfer Roy T. Fielding “ Architectural Styles and Design of Network-based Software Architectur...
REST  è uno  stile architetturale  per applicazioni di rete , un insieme di  vincoli  e  principi  che, se seguiti, portan...
REST : principi <ul><li>Stato e funzionalità sono considerati  Risorse  (recensioni) </li></ul><ul><li>Ogni risorsa è  uni...
REST : le risorse Le risorse sono  fonti di informazioni  accessibili attraverso un  URI . Il  client  può attraverso un  ...
HTTP  è  REST ful ma  REST  non è  HTTP
HTTP GET  /reviews/?filter=letter&letter=a  HTTP/1.1 Host: www.goblins.net Connection: Close HTTP/1.1 200 OK Content-Type:...
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Connection: Close HTTP/1....
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/json Connection: Close HTTP/1...
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: text/yml Connection: Close HTTP/1.1 200 O...
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Accept-Language: it Conne...
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Accept-Encoding: compress...
HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php; q=0.8, application/json,...
 
 
 
MODEL
MODEL VIEW
VIEW
$data = array( 1 => array('ID'=>1, 'title'=>'Agricola', ...), 2 => array('ID'=>2, 'title'=>'Risiko', ...), ... ) //reviews...
/reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER web
/reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER web
/reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER //dispatch.php … $requ...
//ReviewResource.php <?php /** * The Review Collection *  @uri /reviews(/?(.)*)? */ class ReviewsResource extends Resource...
On code
/reviews/5
web
Upcoming SlideShare
Loading in …5
×

A simple ReSTful webservice for the Goblins (v. 0.5)

518 views

Published on

Published in: Self Improvement, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
518
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A simple ReSTful webservice for the Goblins (v. 0.5)

  1. 3. Cos’è REST ?
  2. 4. REST non è un Protocollo un’ Architettura un Software uno Standard un nome carino per Web Services una Buzzword
  3. 5. Re presentational S tate T ransfer Roy T. Fielding “ Architectural Styles and Design of Network-based Software Architectures” Ph.D dissertation, 2000
  4. 6. REST è uno stile architetturale per applicazioni di rete , un insieme di vincoli e principi che, se seguiti, portano come risultato un’ architettura semplice e scalabile
  5. 7. REST : principi <ul><li>Stato e funzionalità sono considerati Risorse (recensioni) </li></ul><ul><li>Ogni risorsa è unica e indirizzabile attraverso un URI (/reviews) </li></ul><ul><li>L’accesso alle risorse avviene tramite un’ interfaccia uniforme </li></ul><ul><ul><li>(GET, POST, PUT, DELETE) </li></ul></ul><ul><li>Un protocollo (HTTP) </li></ul><ul><ul><li>Client-server </li></ul></ul><ul><ul><li>Stateless </li></ul></ul><ul><ul><li>Cacheble </li></ul></ul><ul><ul><li>A livelli </li></ul></ul>
  6. 8. REST : le risorse Le risorse sono fonti di informazioni accessibili attraverso un URI . Il client può attraverso un protocollo di comunicazione standard (ad es. http) ottenere una risorsa dal server. Le risorse sono disponibili in diverse rappresentazioni (ad es. XML, JSON, PNG)
  7. 9. HTTP è REST ful ma REST non è HTTP
  8. 10. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Connection: Close HTTP/1.1 200 OK Content-Type: application/xml; charset=UTF-8 <?xml version= &quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <root> <reviews> <review id= “1&quot; title=“Agricola&quot; > <descrizione>Agricola è un gioco…</descrizione> … </review> <review id= “2&quot; title=“Risiko&quot; > <descrizione>…</descrizione> … </review> </reviews> </root>
  9. 11. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Connection: Close HTTP/1.1 200 OK Content-Type: application/php; charset=UTF-8 Connection: Close a:296:{i:0;a:33:{s:2:&quot;id&quot;;s:4:&quot;3791&quot;;s:4:&quot;date&quot;;s:10:&quot;2008-01-28&quot;;s:5:&quot;title&quot;;s:18:&quot;A Caccia con Papà&quot;;s:8:&quot;reviewer&quot;;s…
  10. 12. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/json Connection: Close HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Connection: Close [{&quot;id&quot;:&quot;3791&quot;,&quot;date&quot;:&quot;2008-01-28&quot;,&quot;title&quot;:&quot;A Caccia con Papu00e0&quot;,&quot;reviewer&quot;: &quot;Lobo&quot;,&quot;email&quot;:&quot;sdp@sdp.net&quot;,&quot;s …
  11. 13. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: text/yml Connection: Close HTTP/1.1 200 OK Content-Type: text/yml; charset=UTF-8 Connection: Close - id: '3791‘ date: '2008-01-28‘ title: 'A Caccia con Papà‘ reviewer: Lobo email: sdp@sdhjp.net score: '0‘ cover: '‘ url: '‘ url_title: '‘ hits: '500‘ …
  12. 14. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Accept-Language: it Connection: Close HTTP/1.1 200 OK Content-Type: application/php; charset=UTF-8 Connection: Close a:296:{i:0;a:33:{s:2:&quot;id&quot;;s:4:&quot;3791&quot;;s:4:&quot;date&quot;;s:10:&quot;2008-01-28&quot;;s:5:&quot;title&quot;;s:18:&quot;A Caccia con Papà&quot;;s:8:&quot;reviewer&quot;;s…
  13. 15. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php Accept-Encoding: compress Connection: Close HTTP/1.1 200 OK Content-Type: application/php; charset=UTF-8 Content-Encoding: compress Vary: Accept-Encoding Connection: Close #@°&%&%%$&%@°...
  14. 16. HTTP GET /reviews/?filter=letter&letter=a HTTP/1.1 Host: www.goblins.net Accept: application/php; q=0.8, application/json, text/yml; q=0.5 Connection: Close HTTP/1.1 200 OK Content-Type: application/php; charset=UTF-8 Connection: Close a:296:{i:0;a:33:{s:2:&quot;id&quot;;s:4:&quot;3791&quot;;s:4:&quot;date&quot;;s:10:&quot;2008-01-28&quot;;s:5:&quot;title&quot;;s:18:&quot;A Caccia con Papà&quot;;s:8:&quot;reviewer&quot;;s…
  15. 20. MODEL
  16. 21. MODEL VIEW
  17. 22. VIEW
  18. 23. $data = array( 1 => array('ID'=>1, 'title'=>'Agricola', ...), 2 => array('ID'=>2, 'title'=>'Risiko', ...), ... ) //reviews.html <?xml version= &quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <root> <reviews> {% for i, r in reviews %} <review id= &quot;{{r.id}}&quot; title=&quot;{{r.title}}&quot; > {% for key, value in r %} <{{key}}>{{value}}</{{key}}> {% endfor %} </review> {% else %} <noresult>No result for this query</noresult> {% endfor %} </reviews> </root> <?xml version= &quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <root> <reviews> <review id= “1&quot; title=“Agricola&quot; > <descrizione>Agricola è un gioco…</descrizione> … </review> <review id= “2&quot; title=“Risiko&quot; > <descrizione>…</descrizione> … </review> </reviews> </root>
  19. 24. /reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER web
  20. 25. /reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER web
  21. 26. /reviews/?filter=letter&letter=a /reviews/5 /reviews/5/comments … .htaccess dispatch.php CONTROLLER //dispatch.php … $request = new Request( $config = array() ); $resource = $request->loadResource(); $response = $resource->exec($request); $response->output(); web
  22. 27. //ReviewResource.php <?php /** * The Review Collection * @uri /reviews(/?(.)*)? */ class ReviewsResource extends Resource { /** * Handle a GET request for this resource * @param Request request * @return Response */ function get($request) { $response = new Response($request); $etag = md5($request->uri); if ($request->ifNoneMatch($etag)) { $response->code = Response::NOTMODIFIED ; } else { $response->code = Response::OK ; $response->addHeader('Content-type', 'text/html; charset=&quot;UTF-8&quot;'); $headers = $this-> selectHeaders ($request); foreach($headers as $key => $value) $response->addHeader($key, $value); $response->addEtag($etag); $response->body = $this-> selectBody ($request); } return $response; } … }
  23. 28. On code
  24. 29. /reviews/5
  25. 30. web

×