What is the 101 HTTP Status Code?
The HTTP status code 101 Switching Protocols is part of the 1xx series, indicating an informational response from the server. It is utilized when the server agrees to upgrade its protocol and is ready to switch to a different protocol specified in the client's request. This status code is commonly associated with the WebSocket protocol, which allows for full-duplex communication channels over a single TCP connection.Conditions for Receiving 101 Switching Protocols.
- Upgrade Request Header: The client sends a request with an Upgrade header, indicating the desire to switch protocols. This header specifies the protocol the client wants to switch to.
- Server Agreement: The server supports the requested protocol and is willing to switch. The server includes the Upgrade header in its response to acknowledge the protocol switch.
How to Handle 101 Switching Protocols?
GET /example HTTP/1.1 Host: example.com Upgrade: websocket Connection: Upgrade
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade
- The most common use case for 101 Switching Protocols is during the establishment of WebSocket connections.
- It can be employed for other scenarios where the client and server agree to switch to a different protocol for enhanced communication.



