Block 3 Übersicht

HTTP-Protokoll

Hypertext Transfer Protocol - Request/Response, Methoden, Status-Codes

HTTP Request

Client → Server
GET /api/data HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: application/json
Connection: keep-alive
\r\n
Methode GET, POST, PUT, DELETE, PATCH...
Pfad Ressource auf dem Server
Version HTTP/1.1 oder HTTP/2

HTTP Response

Server → Client
HTTP/1.1 200 OK
Date: Mon, 27 Nov 2023 12:00:00 GMT
Server: Apache/2.4.41
Content-Type: application/json
Content-Length: 123
\r\n
{ "data": "value" }
2xx Success
3xx Redirect
4xx Client Error
5xx Server Error

HTTP Methoden

GET

Ressource abrufen

Safe, Idempotent

POST

Ressource erstellen

Nicht idempotent

PUT

Ressource ersetzen

Idempotent

PATCH

Teil-Update

Nicht idempotent

DELETE

Ressource löschen

Idempotent

Wichtige Status-Codes

200
OK
Anfrage erfolgreich
301
Moved Permanently
Dauerhafte Umleitung
302
Moved Temporarily
Temporäre Umleitung
400
Bad Request
Fehlerhafte Anfrage
403
Forbidden
Zugriff verweigert
404
Not Found
Ressource nicht gefunden
500
Internal Server Error
Serverfehler

Häufige HTTP-Header

Request Header

Host Domain des Servers
User-Agent Client-Information
Accept Erwarteter Content-Type
Authorization Authentifizierungsdaten
Content-Type Typ des Request-Body

Response Header

Date Zeitpunkt der Response
Server Server-Software
Content-Type MIME-Type der Antwort
Content-Length Länge des Body
Location Umleitungsziel

URL-Aufbau

https:// www.example.com : 443 /path/to/resource ?key=value #anchor
Schema
Protokoll
Host
Domain/IP
Port
80/443
Pfad
Ressource
Query
Parameter
Fragment
Anker

Formelsammlung Kapitel 7.5.2 - HTTP

Kommunikationsprinzip:

  • Request-Response - Client fragt, Server antwortet
  • Zustandslos - Jede Anfrage unabhängig
  • Text-basiert - Menschlich lesbar

Standard Ports:

  • Port 80 - HTTP (unverschlüsselt)
  • Port 443 - HTTPS (TLS/SSL verschlüsselt)