120305 intro-rest
TRANSCRIPT
REST-konforme Schnittstellen für
Web Services
Thrift
Remote Procedure Call
Remote Method Invocation
CORBA
XML-RPC SOAP
REST
REST ist eine Architektur
HTTP ist eine konkrete Implementierung davon
Ressourcenhttp://www.mybank.com/accounts/
http://www.mybank.com/accounts/4582
http://www.mybank.com/accounts/4582/statements/
http://www.mybank.com/accounts/4582/statements/latest
http://www.mybank.com/accounts/4582/transfers
http://www.mybank.com/accounts/4582/transfers/12
http://www.mybank.com/accounts/4582/transfers/12?from=...&to=...
http://www.mybank.com/accounts/4582/transfers/12/recipient
Repräsentationen{ „account“ : {
„id“ : 4582,„firstName“ : „Singh“,„lastName“ : „Darshan“,„balance“ : 25382.20,„openDate“ : „2002-02-20“ }
}
<?xml version=“1.0“?><account><id>4582</id><firstName>Singh</firstName><lastName>Darshan</lastName><balance>25382.20</balance><openDate>2002-02-20</openDate>
</account>
4 Operationen
GET
POST
PUT
DELETE
4 Operationen
GET
POST
PUT
DELETE
safe?
4 Operationen
GET
POST
PUT
DELETE
safe? idempotent?
Hypermedia
Account
Person
Statement
Balance
Transfer Person
Zustandslose Kommunikation
Keine SessionsKeine Cookies
Jede Anfrage enthält alle Informationen, die der Server für die Verarbeitung benötigt.
REST ist nur
ein Paradigma
Häufige „Fehler“
RPC Stil
http://www.mybank.com/accounts/4582?
action=transfer&dest=9811&amount=100
POST Tunneling
http://www.mybank.com/accounts?
action=close&id=4582
Vermischung Ressource und Repräsentation
GET /accounts/4982.json?apikey=912864
GET /accounts/4982Accept: application/jsonX-apikey: 912864
Keine Links
{ „account“ : {
„id“ : 4582,„firstName“ : „Singh“,„lastName“ : „Darshan“,„balance“ : 25382.20,„openDate“ : „2002-02-20“
}}
Nur interne IDs
{ „account“ : {
„id“ : 4582,„owner“ : 56120,„balance“ : 25382.20,„openDate“ : „2002-02-20“
}}
Keine Links zu Sub-Ressourcen
{ „account“ : {
„id“ : 4582,„owner“ : „http//www.mybank.com/clients/561202“,„balance“ : 25382.20,„openDate“ : „2002-02-20“
}}
Korrekt:{ „account“ : {
„id“ : 4582,„owner“ : „http//www.mybank.com/clients/561202“,„statements“ : „http://www.mybank.com/accounts/4582/statements“,„transfers“ : „http://www.mybank.com/accounts/4582/transfers“,„balance“ : 25382.20,„openDate“ : „2002-02-20“
}}
HTTP Status CodesGET /accounts/4982
HTTP/1.1 200 OKContent-Type: application/json
{ „error: { „code“ : 491,
„message“ : „Not authorized“ } }
Zusammenfassung
• Wichtiges Paradigma für moderne APIs
• REST ist offen für Interpretationen
• Entwicklungsframeworks helfen nur wenig