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
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
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
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!
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