IP
TCP
HTTP
Request
Client
Response
Server
Nachrichten
Header
Body
http://my-app.net/api.php
DNS
API Server
213.73.89.123
HTTP Nachrichten
auf Port 80
$ telnet www.hs-bremen.de 80
Trying 194.94.24.5...
Connected to www.hs-bremen.de.
Escape character is '^]'.
GET / http/1.1
Host: www.hs-bremen.de
HTTP/1.1 200 OK
Date: Sat, 20 Feb 2016 17:02:00 GMT
Server: Apache
Accept-Ranges: bytes
X-Mod-Pagespeed: 1.1.23.1-2169
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 204
Content-Type: text/html
<html>...</html>
Connection closed by foreign host.GET / http/1.1
Host: www.hs-bremen.de<CR><LF>
<CR><LF>HTTP/1.1 200 OK
Date: Sat, 20 Feb 2016 17:02:00 GMT
Server: Apache
Accept-Ranges: bytes
X-Mod-Pagespeed: 1.1.23.1-2169
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 204
Content-Type: text/html<CR><LF>
<CR><LF>
<html>...</html><CR><LF>
<CR><LF>GET /api.php?search=cats&breed=british%20shorthair HTTP/1.1
Host: my-app.net
...Query-String
?<key>=<value>&<key>=<value>&...
POST /api.php/cats HTTP/1.1
Host: my-app.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 29
name=Zoe&breed=domestic%20catPOST /api.php/cats HTTP/1.1
Host: my-app.net
Content-Type: application/json
Content-Length: 37
{"name":"Zoe","breed":"domestic cat"} <form action="http://my-app.net/api.php/cats"
enctype="multipart/form-data"
method="post">
<label for="name">Name der Katze?</label>
<input type="text" id="name" name="name">
<label for="pictures">Fotos der Katze?</label>
<input type="file" id="pictures" name="pictures" multiple>
<button type="submit">Speichern</button>
<button type="reset">Abbrechen</button>
</form>
<form action="http://my-app.net/api.php/cats" enctype="multipart/form-data" method="post">
<label for="name">Name der Katze?</label>
<input type="text" id="name" name="name">
<label for="vita">Lebenlauf der Katze?</label>
<input type="file" id="vita" name="vita">
<button type="submit">Speichern</button>
<button type="reset">Abbrechen</button>
</form>
POST /api.php/cats HTTP/1.1
Host: my-app.net
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="name"
Larry
--AaB03x
Content-Disposition: form-data; name="vita"; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--AaB03x--"name" Feld
"vita" Feld
<form action="http://my-app.net/api.php/cats" enctype="multipart/form-data" method="post">
<!-- wie eben -->
<input type="file" id="pictures" name="pictures" multiple>
<!-- wie eben -->
</form>
POST /api.php/cats HTTP/1.1
Host: my-app.net
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="name"
Larry
--AaB03x
Content-Disposition: form-data; name="pictures"
Content-Type: multipart/mixed; boundary=BbC04y
--BbC04y
Content-Disposition: file; filename="img1.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
... contents of img1.jpg ...
--BbC04y
Content-Disposition: file; filename="img2.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
... contents of img2.jpg ...
--BbC04y--
--AaB03x--"name" Feld
Header für "pictures" Feld
Datei 1 aus "pictures"
Datei 2 aus "pictures"
PUT /api.php/cats/1 HTTP/1.1
Host: my-app.net
... body ...
HTTP/1.1 302 FOUND
Date: Sat, 20 Feb 2016 23:02:00 GMT
Location: /api.php/catsDokument
v.d. Leyens Doktor-arbeit
Star Wars
Film
Einkauf
Personal-
einstellungs-
prozess
<schema>:<schema-spezifische-struktur>
Zur allgemeinen und unspezifischen Ressourcen Identifizierung.
Eine Erweiterung der URI, welche internationale Zeichen erlaubt.
Abstrakteste Form eine Resource zu identifizieren. Die URN ist unabhängig von technischen Gegebenheiten und definiert ausschließlich Namensräume für Ressourcen, z.B. urn:isbn:123456789
Eine besondere Art von URI, die vermittelt, wie man mit einer Ressource interagiert.
Zum Beispiel vermittelt http://google.com eine Web-Ressource mit der man über HTTP kommunizieren kann.
Verbreitetes Synonym für Ressource URI innerhalb des Internets.
Sprich: HTTP URI
http://restbucks.com/menu
Menu
Latte: 5 €
Espresso: 4 €
Cookie: 1 €
<html>
<body>
<h1>Menu</h1>
<ul>
<li>Latte: 5€</li>
<li>Espresso: 4€</li>
<li>Cookie: 1€</li>
</ul>
</body>**Menu**
Latte: 5€
Espresso: 4€
Cookie: 1€HTML
Text
http://restbucks.com/order/123
Order
ID: 123
Customer-ID: 5
Coffee: Latte
Payment: 5€
Date: 2016-02-05
<order id="123">
<customer>
http://restbucks/customer/5
</customer>
<coffee>Latte</coffee>
<payment>5€</payment>
<date>2016-02-05</date>
</order>Menu
Ressource
http://restbucks.com/menu
XML Darstellung
JSON Darstellung
Text Darstellung
HTTP Accept Header
= ?
Quelle: REST in Practice, Seite: 14
http://restbucks.com/order/1234http://restbucks.com/order/1234http://restbucks.com/order/{order-id}http://restbucks.com/order/{year}/{month}/{day}Idempotenz ist ein Begriff aus der Mathematik und Informatik. Man bezeichnet ein Element einer Menge, das mit sich selbst verknüpft wieder sich selbst ergibt, als idempotent.
Webservices! REST-API?
aufgegeben
bezahlt
abgeschlossen
ausgeliefert
aktualisiert
| Verb | URI | Aktion |
|---|---|---|
| GET | /order | Liefert die Liste aller Bestellungen |
| POST | /order | Neue Bestellung erstellen und bei Erfolg einen Location Header zur neuen Bestellung zurückgeben. |
| GET | /order/{orderId} | Gibt den Status der angegebenen Bestellung zurück. |
| PUT | /order/{orderId} | Aktualisiert die Bestellung. |
| DELETE | /order/{orderId} | Löscht die Bestellung. |
{
"location": "takeAway",
"items": [
{
"name": "Latte",
"quantity": 1,
"milk": "whole",
"size": "small"
}
]
}POST http://restbucks.com/orderPOST /order HTTP/1.1
Host: restbucks.com
Content-Type: application/json
Content-Length: 157
{ ... }Kunde
Restbucks
POST /order
{...}
201 Created
Location /order/1234
400 Bad Request
500 Internal Error
HTTP/1.1 201 Created
Content-Length: 203
Content-Type: application/json
Date: Wed, 01 Apr 2016 21:45:03 GMT
Location: http://restbucks.com/order/1234
{
"_href": "http://restbucks.com/order/1234",
"location": "takeAway",
"items": [
{
"name": "Latte",
"quantity": 1,
"milk": "whole",
"size": "small"
}
],
"status": "placed"
}HTTP/1.1 200 OK
Content-Length: 203
Content-Type: application/json
Date: Wed, 01 Apr 2016 21:45:03 GMT
{
"_href": "http://restbucks.com/order/1234",
"location": "takeAway",
"items": [
{
"name": "Latte",
"quantity": 1,
"milk": "whole",
"size": "small"
}
],
"status": "served"
}GET /order/1234 HTTP/1.1
Host: restbucks.comHTTP/1.1 200 OK
Content-Length: 203
Content-Type: application/json
Date: Wed, 01 Apr 2016 21:45:03 GMT
{ ... }PUT /order/1234 HTTP/1.1
Host: restbucks.com
{
"location": "takeAway",
"items": [
{
"name": "Latte",
"quantity": 2,
"milk": "whole",
"size": "large"
}
]
}HTTP/1.1 204 No Content
Date: Wed, 01 Apr 2016 21:45:03 GMT
HTTP/1.1 200 OK
Content-Length: 203
Content-Type: application/json
Date: Wed, 01 Apr 2016 21:45:03 GMT
{ ... <Vollständiges DTO> ... }PATCH /order/1234 HTTP/1.1
Host: restbucks.com
{
"location": "inStore",
}HTTP/1.1 204 No Content
Date: Wed, 01 Apr 2016 21:45:03 GMT
DELETE /order/1234 HTTP/1.1
Host: restbucks.comHTTP/1.1 204 No Content
Date: Wed, 01 Apr 2016 21:45:03 GMT
DELETE /order/1234 HTTP/1.1
Host: restbucks.comHTTP/1.1 405 Method Not Allowed
Allow: GET
Date: Wed, 01 Apr 2016 21:45:03 GMT
{
"location": "takeAway",
"items": [
{
"name": "Latte",
"quantity": 1,
"milk": "whole",
"size": "small"
}
],
"status": "served",
"_href": "http://restbucks.com/order/1234",
"_actions": [
{
"action": "pay",
"href": "http://restbucks.com/order/1234/pay",
"method": "POST"
}
]
}GET /payment/1234 HTTP/1.1
Host: restbucks.com401 Unauthorized
WWW-Authenticate: Basic realm="payments@restbucks.com"
# WWW-Authenticate: <Auth-Typ> <Auth-Optionen>GET /payment/1234 HTTP/1.1
Host: restbucks.com
Authorization: Basic Zm9vOmJhcg==base64_encode("<login>:<passwort>");
http://<login>:<password>@my-api.com/
GET /payment/1234 HTTP/1.1
Host: restbucks.com401 Unauthorized
WWW-Authenticate: Digest realm="payments@restbucks.com",
qop="auth",
nonce="1e8c46a7d793433490cb8303f18a86e5",
opaque="ff1eccda9ef442b3b38cabb2435d5967"401 Unauthorized
WWW-Authenticate: Digest realm="payments@restbucks.com",
qop="auth",
nonce="1e8c46a7d793433490cb8303f18a86e5",
opaque="ff1eccda9ef442b3b38cabb2435d5967"401 Unauthorized
WWW-Authenticate: Digest realm="payments@restbucks.com",
qop="auth",
nonce="1e8c46a7d793433490cb8303f18a86e5",
opaque="ff1eccda9ef442b3b38cabb2435d5967"401 Unauthorized
WWW-Authenticate: Digest realm="payments@restbucks.com",
qop="auth",
nonce="1e8c46a7d793433490cb8303f18a86e5",
opaque="ff1eccda9ef442b3b38cabb2435d5967"GET /payment/1234 HTTP/1.1
Host: restbucks.com
Authorization: Digest username="beancounter",
realm="payments@restbucks.com",
nonce="1e8c46a7d793433490cb8303f18a86e5",
uri="/payment/1234"
qop="auth",
nc=00000001,
cnonce="cf45f0087f33bce12332aef430945dff",
response="ff14aa3457acd60aa2091232a98756ff",
opaque="ff1eccda9ef442b3b38cabb2435d5967"GET /payment/1234 HTTP/1.1
Host: restbucks.com
Authorization: Digest username="beancounter",
realm="payments@restbucks.com",
nonce="1e8c46a7d793433490cb8303f18a86e5",
uri="/payment/1234"
qop="auth",
nc=00000001,
cnonce="cf45f0087f33bce12332aef430945dff",
response="ff14aa3457acd60aa2091232a98756ff",
opaque="ff1eccda9ef442b3b38cabb2435d5967"GET /payment/1234 HTTP/1.1
Host: restbucks.com
Authorization: Digest username="beancounter",
realm="payments@restbucks.com",
nonce="1e8c46a7d793433490cb8303f18a86e5",
uri="/payment/1234"
qop="auth",
nc=00000001,
cnonce="cf45f0087f33bce12332aef430945dff",
response="ff14aa3457acd60aa2091232a98756ff",
opaque="ff1eccda9ef442b3b38cabb2435d5967"HTTPS!
1 : 1
GET /order/1234?apikey=<some-pretty-long-cryptic-api-key> HTTP/1.1
Host: restbucks.comHTTP/1.1 410 Gone
Date: Fri, 14 Oct 2016 08:00:00 GMT