Zum Hauptinhalt springen

Anhang A. Ressourcendarstellung und Darstellungsdaten

The following examples show how representation metadata, content transformations, and methods impact the message and content. These examples a not exhaustive.

Die folgenden Beispiele zeigen, wie sich Repräsentationsmetadaten, Inhaltstransformationen und Methoden auf die Nachricht und den Inhalt auswirken. Diese Beispiele sind nicht erschöpfend.

Unless otherwise indicated, the examples are based on the JSON object {"hello": "world"} followed by an LF. When the content contains non-printable characters (e.g., when it is encoded), it is shown as a sequence of hex-encoded bytes.

Sofern nicht anders angegeben, basieren die Beispiele auf dem JSON-Objekt {"hello": "world"} gefolgt von einem LF. Wenn der Inhalt nicht druckbare Zeichen enthält (z. B. wenn er codiert ist), wird er als Folge von hexadezimal codierten Bytes angezeigt.

Consider a client that wishes to upload a JSON object using the PUT method. It could do this using the application/json Content-Type without any content coding.

Betrachten Sie einen Client, der ein JSON-Objekt mit der PUT-Methode hochladen möchte. Er könnte dies mit dem Content-Type application/json ohne Inhaltscodierung tun.

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Length: 19

{"hello": "world"}

Figure 1: Request Containing a JSON Object without Any Content Coding

Abbildung 1: Anfrage mit einem JSON-Objekt ohne Inhaltscodierung

However, the use of content coding is quite common. The client could also upload the same data with a GZIP coding (Section 8.4.1.3 of [HTTP]). Note that in this case, the Content-Length contains a larger value due to the coding overheads.

Die Verwendung von Inhaltscodierung ist jedoch recht verbreitet. Der Client könnte dieselben Daten auch mit einer GZIP-Codierung hochladen (Abschnitt 8.4.1.3 von [HTTP]). Beachten Sie, dass in diesem Fall die Content-Length aufgrund des Codierungsaufwands einen größeren Wert enthält.

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Encoding: gzip
Content-Length: 39

1F 8B 08 00 88 41 37 64 00 FF
AB 56 CA 48 CD C9 C9 57 B2 52
50 2A CF 2F CA 49 51 AA E5 02
00 D9 E4 31 E7 13 00 00 00

Figure 2: Request Containing a GZIP-Encoded JSON Object

Abbildung 2: Anfrage mit einem GZIP-codierten JSON-Objekt

Sending the GZIP-coded data without indicating it via Content-Encoding means that the content is malformed. In this case, the server can reply with an error.

Das Senden der GZIP-codierten Daten ohne Angabe über Content-Encoding bedeutet, dass der Inhalt fehlerhaft ist. In diesem Fall kann der Server mit einem Fehler antworten.

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json

Content-Length: 39

1F 8B 08 00 88 41 37 64 00 FF
AB 56 CA 48 CD C9 C9 57 B2 52
50 2A CF 2F CA 49 51 AA E5 02
00 D9 E4 31 E7 13 00 00 00

Figure 3: Request Containing Malformed JSON

Abbildung 3: Anfrage mit fehlerhaftem JSON

HTTP/1.1 400 Bad Request

Figure 4: An Error Response for Malformed Content

Abbildung 4: Eine Fehlerantwort für fehlerhaften Inhalt

A Range-Request affects the transferred message content. In this example, the client is accessing the resource at /entries/1234, which is the JSON object {"hello": "world"} followed by an LF. However, the client has indicated a preferred content coding and a specific byte range.

Eine Range-Anfrage wirkt sich auf den übertragenen Nachrichteninhalt aus. In diesem Beispiel greift der Client auf die Ressource unter /entries/1234 zu, bei der es sich um das JSON-Objekt {"hello": "world"} gefolgt von einem LF handelt. Der Client hat jedoch eine bevorzugte Inhaltscodierung und einen bestimmten Bytebereich angegeben.

GET /entries/1234 HTTP/1.1
Host: foo.example
Accept-Encoding: gzip
Range: bytes=1-7

Figure 5: Request for Partial Content

Abbildung 5: Anfrage für Teilinhalt

The server satisfies the client request by responding with a partial representation (equivalent to the first 10 bytes of the JSON object displayed in whole in Figure 2).

Der Server erfüllt die Client-Anfrage, indem er mit einer teilweisen Darstellung antwortet (entspricht den ersten 10 Bytes des in Abbildung 2 vollständig angezeigten JSON-Objekts).

HTTP/1.1 206 Partial Content
Content-Encoding: gzip
Content-Type: application/json
Content-Range: bytes 0-9/39

1F 8B 08 00 A5 B4 BD 62 02 FF

Figure 6: Partial Response from a GZIP-Encoded Representation

Abbildung 6: Teilantwort aus einer GZIP-codierten Darstellung

Aside from content coding or range requests, the method can also affect the transferred message content. For example, the response to a HEAD request does not carry content, but this example case includes Content-Length; see Section 8.6 of [HTTP].

Abgesehen von Inhaltscodierung oder Range-Anfragen kann auch die Methode den übertragenen Nachrichteninhalt beeinflussen. Zum Beispiel enthält die Antwort auf eine HEAD-Anfrage keinen Inhalt, aber dieser Beispielfall enthält Content-Length; siehe Abschnitt 8.6 von [HTTP].

HEAD /entries/1234 HTTP/1.1
Host: foo.example
Accept: application/json
Accept-Encoding: gzip

Figure 7: HEAD Request

Abbildung 7: HEAD-Anfrage

HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip
Content-Length: 39

Figure 8: Response to HEAD Request (Empty Content)

Abbildung 8: Antwort auf HEAD-Anfrage (leerer Inhalt)

Finally, the semantics of a response might decouple the target URI from the enclosed representation. In the example below, the client issues a POST request directed to /authors/, but the response includes a Content-Location header field indicating that the enclosed representation refers to the resource available at /authors/123. Note that Content-Length is not sent in this example.

Schließlich kann die Semantik einer Antwort die Ziel-URI von der enthaltenen Darstellung entkoppeln. Im folgenden Beispiel sendet der Client eine POST-Anfrage an /authors/, aber die Antwort enthält ein Content-Location-Headerfeld, das angibt, dass sich die enthaltene Darstellung auf die unter /authors/123 verfügbare Ressource bezieht. Beachten Sie, dass Content-Length in diesem Beispiel nicht gesendet wird.

POST /authors/ HTTP/1.1
Host: foo.example
Accept: application/json
Content-Type: application/json

{"author": "Camilleri"}

Figure 9: POST Request

Abbildung 9: POST-Anfrage

HTTP/1.1 201 Created
Content-Type: application/json
Content-Location: /authors/123
Location: /authors/123

{"id": "123", "author": "Camilleri"}

Figure 10: Response with Content-Location Header

Abbildung 10: Antwort mit Content-Location-Header