The HTTP Status Code 418 I'm a teapot
is a unique and non-standard status code that was originally defined in the RFC 2324 as part of the Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0). HTCPCP was an April Fools’ Day joke published in 1998, and the 418 I'm a teapot
status code was included as a humorous addition. Despite its non-serious origins, this status code has been widely adopted by developers and is often used as an easter egg within various applications and APIs.
When to Use 418 I’m a teapot
As a non-standard status code, the 418 I'm a teapot
status code should not be used in regular HTTP applications or APIs. However, it can be used for fun or as an easter egg in your application, especially when an unexpected or nonsensical request is received.
Example Request and Response
In this example, we will demonstrate a client sending an HTTP request to a server that implements the HTCPCP protocol. The client is attempting to brew coffee, but the server is a teapot and cannot brew coffee. The server responds with the 418 I'm a teapot
status code to indicate that it cannot process the request.
Request
POST /coffee HTTP/1.1
Host: example.com
Content-Type: application/htcpcp
Content-Length: 15
start=brew&type=coffee
Response
HTTP/1.1 418 I'm a teapot
Content-Type: text/plain
Content-Length: 38
I'm a teapot and cannot brew coffee.
In the example above, the client sends a POST
request to the /coffee
resource, attempting to brew coffee. However, the server is a teapot and cannot brew coffee, so it responds with the 418 I'm a teapot
status code and a plain text message explaining the situation.
Implementing 418 I’m a teapot in Your Application
While the use of the 418 I'm a teapot
status code is not recommended for serious applications, you can still implement it as an easter egg or for fun. Below is an example of how to implement the 418 I'm a teapot
status code in a simple Express.js application.
const express = require('express');
const app = express();
app.post('/coffee', (req, res) => {
res.status(418).send("I'm a teapot and cannot brew coffee.");
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
In this example, an Express.js server listens for POST
requests to the /coffee
resource and responds with the 418 I'm a teapot
status code and a plain text message.
Summary
The 418 I'm a teapot
status code is a non-standard and humorous HTTP status code that originated from the HTCPCP protocol as an April Fools’ Day joke. It is not intended for use in serious applications or APIs, but can be implemented as an easter egg or for fun when an unexpected or nonsensical request is received.