Content Negotiation
Inhaltsverhandlung
Inhaltsverhandlung ist, wie HTTP eine Version einer Ressource aus den Vorlieben des Clients und den verfügbaren Formaten des Servers auswählt.
Ein weiteres Beispiel
Eine Bericht-API sendet `application/json` oder `text/csv` basierend auf `Accept`. Sie gibt 406 zurück, wenn keines funktioniert, und fügt `Vary: Accept` hinzu. Dies verhindert, dass ein Cache CSV an einen JSON-Client sendet. Die Sprache wird separat gewählt, und jede Antwort hat einen klaren `Content-Type`.
Hauptteile
- 01Client-Einstellungen
- 02verfügbare Darstellungen
- 03Ausgewählte Antwort und Vary
Verwenden Sie es, wenn
Verwenden Sie standardisierte Anfrage-Header, wenn eine Ressource wirklich unterschiedliche Medien-, Sprach-, Kodierungs- oder Präferenzversionen hat.
Nutze es nicht, wenn
Erstellen Sie keine Versionen, die Caches nicht unterscheiden können. Ignorieren Sie nicht stillschweigend einen erforderlichen Medientyp, den der Server nicht unterstützt.
In Code verwendeter Name
Accept / Accept-Language / Accept-Encoding + Content-Type / Content-Language + Vary Vor dem Ausliefern
Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback.
Outcome: Complete the task with Inhaltsverhandlung (Content Negotiation). User context: Eine Bericht-API sendet `application/json` oder `text/csv` basierend auf `Accept`. Sie gibt 406 zurück, wenn keines funktioniert, und fügt `Vary: Accept` hinzu. Dies verhindert, dass ein Cache CSV an einen JSON-Client sendet. Die Sprache wird separat gewählt, und jede Antwort hat einen klaren `Content-Type`. Technical concept or control: Inhaltsverhandlung (Content Negotiation). Why it fits: Verwenden Sie standardisierte Anfrage-Header, wenn eine Ressource wirklich unterschiedliche Medien-, Sprach-, Kodierungs- oder Präferenzversionen hat. Do not use it when: Erstellen Sie keine Versionen, die Caches nicht unterscheiden können. Ignorieren Sie nicht stillschweigend einen erforderlichen Medientyp, den der Server nicht unterstützt. Engineering requirements: Define inputs, outputs, contracts, and rules that must always hold. Set authorization and input checks. Define failures, timeouts, retries, one-time effects, data moves, and compatibility limits. Operations: Add useful signals and logs that hide sensitive data. Set capacity limits and write an operator guide. Test recovery and rollback. Acceptance criteria: Contract and failure-path tests pass. Data and authorization rules still hold during retries and partial failures. Check performance limits, monitoring, recovery, and rollback. Evidence and limits (evidence boundary): Der Standard deckt nur den aufgeführten Umfang ab. Er wählt nicht den visuellen Stil, die Produktentscheidung oder das Vibulary-Beispiel aus. Unknowns to confirm: Where the code runs, data stores, traffic shape, consistency needs, and the security boundary. Also confirm the compatibility period, service goals, and rollback limits.
Diese Anfrage prüfen
Review how Inhaltsverhandlung (Content Negotiation) is used now. Definition: Inhaltsverhandlung ist, wie HTTP eine Version einer Ressource aus den Vorlieben des Clients und den verfügbaren Formaten des Servers auswählt. Release checks: Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback. Before changing code, list the evidence, gaps, severity, and the smallest safe fix.