How to Test WebSocket in Postman: Step-by-Step Guide
To test a
WebSocket in Postman, open Postman and select the WebSocket Request tab. Enter the WebSocket URL, connect, then send and receive messages using the interface. Postman allows you to send text or JSON messages and view real-time responses.Syntax
Postman uses a simple interface to test WebSocket connections. The main parts are:
- WebSocket URL: The address starting with
ws://orwss://to connect. - Connect Button: Starts the WebSocket connection.
- Message Input: Where you type the message to send.
- Send Button: Sends the message to the server.
- Response Panel: Shows messages received from the server in real time.
text
ws://example.com/socket // Connect to this URL // Send messages as plain text or JSON // Receive messages live in the response panel
Example
This example shows how to connect to a public echo WebSocket server, send a message, and receive the same message back.
text
1. Open Postman and click <strong>New</strong> > <strong>WebSocket Request</strong>. 2. Enter the URL: <code>wss://echo.websocket.events</code> 3. Click <strong>Connect</strong>. 4. In the message input, type: <code>{"message": "Hello, WebSocket!"}</code> 5. Click <strong>Send</strong>. 6. Observe the response panel showing the echoed message.
Output
{"message": "Hello, WebSocket!"}
Common Pitfalls
- Wrong URL scheme: Use
ws://orwss://, nothttp://orhttps://. - Not clicking Connect: You must connect before sending messages.
- Incorrect message format: Ensure your message matches the server's expected format (text or JSON).
- Ignoring server responses: Watch the response panel to verify server replies.
javascript
/* Wrong way: Trying to send message before connecting */ // No connection established // pm.sendMessage('{"test": "data"}'); /* Right way: Connect first, then send message */ // Connect button clicked // Then send message in input and click Send
Quick Reference
| Action | Description |
|---|---|
| Enter WebSocket URL | Use ws:// or wss:// scheme |
| Click Connect | Establish the WebSocket connection |
| Type message | Enter text or JSON to send |
| Click Send | Send message to server |
| View Response | See server messages live |
Key Takeaways
Always use ws:// or wss:// URLs to connect to WebSocket servers in Postman.
Click the Connect button before sending any messages to establish the connection.
Send messages as plain text or JSON depending on server requirements.
Monitor the response panel to verify server replies in real time.
Avoid sending messages before connection or using incorrect URL schemes.