62
RESTING ON HTTP DEVELOPER WEEK - 17.06.2015

RESTing on HTTP

Embed Size (px)

Citation preview

RESTING ON HTTPDEVELOPER WEEK - 17.06.2015

WHO AM I?Maximilian Berghoff

Mayflower GmbH (Würzburg)

@[email protected]

ABOUT?

REST = HTTP?

HTTP

GET /info HTTP/1.1Host: www.expamle.devContent­Type: text/html

Header Request

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF­8"> <title>Information</title></head><body> <h1>Information about this page</h1> <p>Here you will get your information</p></body></html>

Content der Response

HTTP/1.1 200 OKContent­Type: text/html; charset=UTF­8..

Header Response

STATUS CODES1XX - Bearbeitung dauert an (Intermediate)2XX - Anfrage Erfolgreich3XX - Umleitungen4XX - Fehler in der Anfrage/beim Client5XX - Fehler am Server

METHOD

SAVE METHOD?

GET

GET /BLOG/2/EDIT

GET /BLOG/2/EDIT

POST / PUT

POST

POST /users HTTP/1.1Host: www.example.devContent­Type: application/json

"firstName": "Max", "lastName": "Berghoff"

POST request

HTTP/1.1 201 CreatedContent­Type: application/json;Content­Location: /users/3

"id": "3", "firstName": "Max", "lastName": "Berghoff"

POST response

PUT

PUT /users/3 HTTP/1.1Host: www.example.devContent­Type: application/json

"firstName": "Max", "lastName": "Berghoff", "email": "[email protected]"

PUT request

HTTP/1.1 200 OKContent­Type: application/json;

"id": "3", "firstName": "Max", "lastName": "Berghoff", "email": "[email protected]"

POST response

PATCH

POST / PUT / PATCH

DELETE

DELETE /users/3 HTTP/1.1Host: www.example.dev

DELETE request

HTTP/1.1 204 No ContentLocation: /users

DELETE response

OPTIONS

HEAD

ROY FIELDINGHTTP Spezification

DISERTATIONARCHITECTURAL STYLES AND THE DESIGN OF NETWORK-BASED SOFTWARE ARCHITECTURES

DOCTOR OF PHILOSOPHY, 2000

4 CONSTRAINTS

1.ADRESSIERBARKEIT

2.REPRÄSENTATIONEN

3.ZUSTANDSLOSIGKEIT

4.OPERATIONEN

RESOURCEN?

JEDE INFORMATION KANNRESOURCE SEIN

(HTML) DokumentBildListe von Resourcen

Alles was Ziel einer Referenz/eines Link sein kann.

REPRÄSENTATIONEN

"userId": "3", "username": "ElectricMaxxx", "firstName": "Max", "lastName": "Berghoff", "email": "[email protected]"

User als JSON

<user> <userId>3</userId> <userName>ElectricMaxxx</userName> <firstName>Maximilian</firstName> <lastName>Berghoff</lastName> <email>[email protected]</email></user>

User als XML

<ul> <li> <strong>Username: </strong> ElectricMaxxx </li> <li> <strong>FirstName: </strong> Max </li> <li> <strong>LastName: </strong> Berghoff </li> <li> <strong>Email: </strong> [email protected] </li></ul>

User als HTML in einem Profil

WIE ERHALTE ICH DIEGEWÜNSCHTE

REPRÄSENTATION?

IN DER URL/users/3.jsonOder /users/3.xmlOder /users/3.html

IM HEADERGET /users/3Content-Type: application/jsonOder Content-Type: application/xmlOder Content-Type: text/html

WIE SOLL RESOURCEAUSSEHEN?

HATEOAS

HYPERMEDIAAS THE ENGINE OF

APPLICATION STATE

WTF?

<?xml version="1.0"?><user> <userName>ElectricMaxxx</userName> <firstName>Maximilian</firstName> <lastName>Berghoff</lastName> <email>[email protected]</email> <link rel="groups" href="/users/3/groups" /> <link rel="roles" href="/users/3/roles" /> <link rel="orders" href="/users/3/orders" /></user>

JSON ?HAL Spezifikation

"_links": "self": "href": "/users/3" ,"userId": "3","_embedded": "orders": [ "_links": "self": "href": "users/3/orders/123" ], "groups": [ "_links": "self": "href": "users/3/orders/2" ]

ZURÜCK AUF NULL

GET /users/3 HTTP/1.1Host: www.expamle.devContent­Type: application/xml

Request auf User mit der ID 3

HTTP/1.1 200 OKContent­Type: application/xml

<?xml version="1.0"?><user> <userName>ElectricMaxxx</userName> <firstName>Maximilian</firstName> <lastName>Berghoff</lastName> <email>[email protected]</email> <link rel="groups" href="/users/3/groups" /> <link rel="roles" href="/users/3/roles" /> <link rel="orders" href="/users/3/orders" /></user>

Anwort des Services in XML

CONTRAINTS ERFÜLLT-> REST = HTTP?

NEIN!!!

HYPETEXT TRANSFERPROTOCOL

REPRESENTATIONALSTATE TRANSFER

I LOVE

RESTING ON HTTP

QUESTIONS ?Ask now!Twitter: @ElectricMaxxxMail: [email protected]

THANK YOU!

< <