🔄
101
Switching Protocols
Example HTTP Response
HTTP Response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: UpgradeCommon Causes
- Upgrading from HTTP to WebSocket
- Switching to HTTP/2
- Client requested protocol change via Upgrade header
Technical Details
What does this mean?
Time for a costume change! The server is switching outfits to speak a different language with you.
Technical Definition
The server is switching to a different protocol as requested by the client.
RFC Says
"The 101 (Switching Protocols) status code indicates that the server understands and is willing to comply with the client's request, via the Upgrade header field, for a change in the application protocol being used on this connection."
Plain English:
The server agrees to switch to a different protocol as you requested. Most commonly used when upgrading from HTTP to WebSocket for real-time bidirectional communication.
Code Snippets
Ready-to-use code for returning this HTTP status in your application:
Node.js
// Express.js
app.get('/example', (req, res) => {
res.status(101).json({
error: 'Switching Protocols',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(101, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Switching Protocols',
message: 'Your error message here'
}));
}).listen(3000);