120305 intro-rest

22
REST-konforme Schnittstellen für Web Services

Transcript of 120305 intro-rest

Page 1: 120305 intro-rest

REST-konforme Schnittstellen für

Web Services

Page 2: 120305 intro-rest

Thrift

Remote Procedure Call

Remote Method Invocation

CORBA

XML-RPC SOAP

Page 3: 120305 intro-rest

REST

Page 4: 120305 intro-rest

REST ist eine Architektur

HTTP ist eine konkrete Implementierung davon

Page 6: 120305 intro-rest

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>

Page 7: 120305 intro-rest

4 Operationen

GET

POST

PUT

DELETE

Page 8: 120305 intro-rest

4 Operationen

GET

POST

PUT

DELETE

safe?

Page 9: 120305 intro-rest

4 Operationen

GET

POST

PUT

DELETE

safe? idempotent?

Page 10: 120305 intro-rest

Hypermedia

Account

Person

Statement

Balance

Transfer Person

Page 11: 120305 intro-rest

Zustandslose Kommunikation

Keine SessionsKeine Cookies

Jede Anfrage enthält alle Informationen, die der Server für die Verarbeitung benötigt.

Page 12: 120305 intro-rest

REST ist nur

ein Paradigma

Page 13: 120305 intro-rest

Häufige „Fehler“

Page 14: 120305 intro-rest

RPC Stil

http://www.mybank.com/accounts/4582?

action=transfer&dest=9811&amount=100

Page 16: 120305 intro-rest

Vermischung Ressource und Repräsentation

GET /accounts/4982.json?apikey=912864

GET /accounts/4982Accept: application/jsonX-apikey: 912864

Page 17: 120305 intro-rest

Keine Links

{ „account“ : {

„id“ : 4582,„firstName“ : „Singh“,„lastName“ : „Darshan“,„balance“ : 25382.20,„openDate“ : „2002-02-20“

}}

Page 18: 120305 intro-rest

Nur interne IDs

{ „account“ : {

„id“ : 4582,„owner“ : 56120,„balance“ : 25382.20,„openDate“ : „2002-02-20“

}}

Page 19: 120305 intro-rest

Keine Links zu Sub-Ressourcen

{ „account“ : {

„id“ : 4582,„owner“ : „http//www.mybank.com/clients/561202“,„balance“ : 25382.20,„openDate“ : „2002-02-20“

}}

Page 20: 120305 intro-rest

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“

}}

Page 21: 120305 intro-rest

HTTP Status CodesGET /accounts/4982

HTTP/1.1 200 OKContent-Type: application/json

{ „error: { „code“ : 491,

„message“ : „Not authorized“ } }

Page 22: 120305 intro-rest

Zusammenfassung

• Wichtiges Paradigma für moderne APIs

• REST ist offen für Interpretationen

• Entwicklungsframeworks helfen nur wenig