← Back to Chapters

HTTP 101 Switching Protocols

? HTTP 101 Switching Protocols

? Quick Overview

HTTP 101 Switching Protocols is an informational status code indicating that the server agrees to switch protocols as requested by the client.

? Key Concepts

  • Part of the 1xx Informational status code family
  • Used during protocol upgrades
  • Commonly associated with WebSockets
  • Triggered by the Upgrade request header

? Syntax / Theory

The client requests a protocol change using the Upgrade header. If the server supports the requested protocol, it responds with 101 Switching Protocols.

? Code Example(s)

? View Code Example
// HTTP request asking the server to switch to WebSocket
GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade

? Live Output / Explanation

Server Response

The server replies with HTTP/1.1 101 Switching Protocols, confirming the protocol upgrade.

? Interactive Protocol Flow

? View Flow Example
// Protocol switching sequence
Client → HTTP Request (Upgrade header)
Server → 101 Switching Protocols
Connection → New Protocol Active

? Interactive Simulator

Click the button below to visualize how the Client and Server handshake works in real-time.

? Status: HTTP/1.1 Standard
// Console ready... waiting for user input.

? Use Cases

  • WebSocket connections
  • HTTP/2 upgrades
  • Real-time communication systems
  • Low-latency bidirectional data transfer

? Tips & Best Practices

  • Ensure both client and server support the new protocol
  • Always validate Upgrade headers securely
  • Use TLS when upgrading to sensitive protocols

? Try It Yourself

  • Create a simple WebSocket server
  • Inspect the 101 response using browser DevTools
  • Test protocol upgrades with curl or Postman