[ADP-129] Expect
NOTICE!
Upon further investigation, we have determined that the Expect header and its associated status code are not recommended for typical API design. For more flexible request handling, we recommend using the Prefer header instead (see ADP-136).
Overview
The Expect HTTP header is used by clients to indicate certain expectations about how the server should handle the request. The primary use of this header is to inform the server that the client expects a 100-continue response before sending the request body. This guideline outlines how and when to use the Expect header in our API.
Usage of Expect Header
Purpose:
- The
Expectheader is primarily used to avoid sending large request bodies to the server when it is not certain that the server will accept the request. By using theExpect: 100-continueheader, the client asks the server to verify that it can handle the request before the client sends the request body.
- The
Syntax:
The header should be used in the following format:
httpExpect: 100-continue
When to Use:
- Use the
Expectheader when sending large payloads, such as file uploads, to minimize the risk of sending data that the server will ultimately reject. - It is especially useful in scenarios where network bandwidth is limited or where the cost of sending large amounts of data is high.
- Use the
Server Behavior:
- Upon receiving a request with the
Expect: 100-continueheader, the server should:- Respond with a
100 Continuestatus code if it is ready to receive the request body. - Respond with a final status code (e.g.,
417 Expectation Failed,4xx, or5xxerrors) if it cannot process the request as expected.
- Respond with a
- Upon receiving a request with the
Client Behavior:
- The client should:
- Wait for a
100 Continueresponse before sending the request body. - If the server responds with a
417 Expectation Failedor any other error status, the client should not send the request body. - Handle any errors appropriately based on the server's response.
- Wait for a
- The client should:
Error Responses:
- All error responses should conform to the HTTP Problem (RFC 9457) specification. Please refer ADP-401: HTTP Problem Basics.
Example
Client Request:
POST /upload HTTP/1.1
Host: api.example.com
Content-Length: 10485760
Expect: 100-continue
Content-Type: application/octet-stream
[Request body not sent yet]Server Response (if the server is ready to accept the request body):
HTTP/1.1 100 ContinueClient Action:
- Upon receiving
100 Continue, the client proceeds to send the request body.
Server Response (if the server cannot process the request):
HTTP/1.1 417 Expectation Failed
Content-Type: application/problem+json
{
"type": "https://example.com/probs/cannot-process",
"title": "Unable to process request",
"status": 417,
"detail": "The server is currently unable to handle the request for this upload size",
"instance": "/upload/1234"
}Client Action:
- Upon receiving
417 Expectation Failed, the client aborts the request and does not send the request body.
Reference
Changelog
2025.01.16: Retiring this for API design