conditional request
An HTTP request that the server carries out only if a condition in its headers is true, such as If-None-Match or If-Match.
In more detail
Conditional reads save bandwidth: the server replies 304 when the client already has the current version. Conditional writes prevent lost updates: the server replies 412 when the version the client read is no longer current.
Example
In the browser: An unchanged resource costs only a short 304 Not Modified reply instead of the whole body.Related terms
- If-None-Match — The request header that sends back an ETag and asks the server to answer 304 Not Modified if that version is still current.
- If-Match — The request header that makes a write conditional: the server applies it only if the resource still has the ETag the client sends.
- ETag — A response header holding an opaque tag that names one exact version of a representation, such as ETag: "1".
- 412 Precondition Failed — The HTTP status meaning a condition in the request headers, such as If-Match, was not true, so nothing was changed.
- Cache-Control — The HTTP header that states the caching policy for a response, such as private, max-age=0 or no-store.
- HTTP cache — A store that keeps HTTP responses and reuses them for later requests, following the rules the server sends in Cache-Control.
Taught in
- Caching And Conditional Requests — Modern API Architecture: REST, GraphQL & gRPC
- The Fetch API: Streaming Responses, HTTP Caching And Keepalive — Frontend Architecture & Web Platform