120305 intro-rest

Preview:

Citation preview

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

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

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