The 300 Multiple Choices
HTTP status code is a server response indicating that the requested resource has multiple representations available, and the server is unable to choose the most suitable one for the client. This status code is part of the HTTP/1.1 standard, defined in RFC 7231.
When to Use 300 Multiple Choices
The 300 Multiple Choices
status code is used when a single resource has multiple representations, and the server cannot automatically determine the best representation for the client. This can occur in situations such as:
- Content negotiation: The server might support multiple content types (e.g., HTML, JSON, XML) for a single resource, but the client’s
Accept
header does not indicate a clear preference. - Language negotiation: The resource might be available in multiple languages, and the client’s
Accept-Language
header does not specify a preferred language. - Other situations where the server cannot decide the most appropriate representation based on the client’s request headers.
Server Response with Alternatives
When responding with a 300 Multiple Choices
status code, the server should provide a list of alternative representations for the client to choose from. This list can be included in the response body, using a format understood by the client (e.g., HTML, JSON, XML), or in the Link
header field, using the rel="alternate"
attribute.
Example: Response with HTML Body
HTTP/1.1 300 Multiple Choices
Content-Type: text/html
<!DOCTYPE html>
<html>
<head>
<title>Multiple Choices</title>
</head>
<body>
<h1>Multiple Choices</h1>
<p>Please choose one of the following formats:</p>
<ul>
<li><a href="/resource.json">JSON</a></li>
<li><a href="/resource.xml">XML</a></li>
</ul>
</body>
</html>
Example: Response with Link Header
HTTP/1.1 300 Multiple Choices
Content-Type: text/plain
Link: </resource.json>; rel="alternate"; type="application/json",
</resource.xml>; rel="alternate"; type="application/xml"
Please choose one of the following formats:
- JSON: /resource.json
- XML: /resource.xml
Client Handling of 300 Multiple Choices
When a client receives a 300 Multiple Choices
response, it can either:
- Prompt the user to select a preferred representation from the list of alternatives.
- Use heuristics or other methods to automatically select a representation, based on factors such as content type, language, or other criteria.
Once the client has chosen a representation, it can issue a new request for that specific representation, using the provided URL or modifying the request headers as needed.
Summary
The 300 Multiple Choices
HTTP status code is used when a requested resource has multiple representations available, and the server cannot determine the most suitable one for the client. The server should provide a list of alternatives in the response body or the Link
header field. Clients can then either prompt the user to choose a representation or use heuristics to automatically select one, and issue a new request for the chosen representation.