HTTP 300 Multiple Choices

Overview

The HTTP 300 Multiple Choices status code indicates that multiple options for the resource that the client may follow are available. It could be used to present different format options for a video, for instance.

Purpose

The HTTP 300 response allows a server to present a list of resource representation choices to the client, typically when multiple options are available for the requested resource.

Usage

Client Behavior:

  1. Send Request: The client sends an HTTP request for a resource.
  2. Receive Response: The client receives the HTTP 300 status code along with a list of available options.

Server Behavior:

  1. Evaluate Request: The server determines that multiple representations of the resource are available.
  2. Send Response: The server sends a 300 Multiple Choices response, often with a list of resource options and their corresponding URLs.

Scenarios

  • Format Options: Used when different formats of a resource are available (e.g., JPG, PNG, SVG for an image).
  • Language Options: Offering different language versions of a resource.

Sequence Diagram

Illustrating the process for an HTTP 300 response:

sequenceDiagram
    participant Client
    participant Server as Web Server

    Note over Client: Client requests a resource
    Client->>Server: GET /resource HTTP/1.1
    Note over Server: Server has multiple representations
    Server->>Client: HTTP/1.1 300 Multiple Choices
    Server->>Client: List of available options

Curl Request and Response Example

Requesting a resource using Curl where multiple choices might be available:

curl -i http://example.com/resource
# Expected response: HTTP/1.1 300 Multiple Choices
# Followed by a list of available options

PHP cURL Request and Response Example

PHP script using cURL to request a resource that could have multiple choices:

<?php
$ch = curl_init('http://example.com/resource');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 300) {
    echo "Multiple choices available for the requested resource.";
}
curl_close($ch);
?>

Python Request and Response Example

Python script to send a GET request and handle a 300 Multiple Choices response:

import requests
response = requests.get('http://example.com/resource')
if response.status_code == 300:
    print("Multiple choices available for the requested resource")

Apache Configuration for HTTP 300 Multiple Choices

Apache configuration to handle requests that may result in a 300 Multiple Choices response:

<VirtualHost *:80>
    ServerName example.com
    # Configuration directives...
</VirtualHost>

NGINX Configuration for HTTP 300 Multiple Choices

Setting up NGINX to handle requests that could return a 300 Multiple Choices response:

server {
    listen 80;
    server_name example.com;
    location /resource {
        # Directives to handle multiple representations
        # ...
    }
}

HTTP 226 IM Used HTTP 301 Moved Permanently


 

Free Weekly

Newsletter

Join my weekly newsletter for the latest in tech! You'll get neat coding tricks, trend updates, career advice, SaaS reviews, crypto, bitcoin, and financial tips. All straight to your inbox, designed to keep you ahead.