Testing Web Sockets with Postman

How to test your Socket.io server locally

Kyle Krupp
3 min readMar 18, 2022

Postman is a popular desktop utility for simulating server requests in the absence of a client or user interface. The electron-based tool is widely used to make HTTP requests in testing a standard REST or GraphQL API. This functionality is instrumental in speeding up the modern development process buy giving you a lightweight means to test your application as you build it out.

With the rise of real-time applications, such as chat services, project management software, collaboration tools, etc. so has come the rise of Web Sockets and the popular Socket.io framework.

Let’s say you’ve built an amazing Node.js + Socket.io server with all kinds of real time functionality. You might be wondering … how do I test this? Surely you can have a comprehensive testing suite with Jest, but how do you ensure the actual WebSockets protocol is working before your API is deployed to production? With a traditional REST API, we know we can expose an endpoint in the from of a URL and manually execute and HTTP verb (GET, POST, PATCH) against it, but for WebSockets there are no endpoints, only events that dictate functionality.

Soo — how to test.. events?

Start by creating a new request in Postman

Select the “New” button (next to “Import”)

Then, specify that your socket connection is going to be a Socket.io connection

Select “Socket.IO” from the dropdown

Depending on which version your Socket.io server is, you’ll need to adjust Client version in the settings:

For this example my sever is v2, so my client needs to match that

Connect to your Socket.io server by proving the URL of whatever your server is running on, for this local example it is localhost:3001

Successful connection to our local Socket.io Node server

Finally, provide mock events to your server by providing the event name and payload. You can format your payload as Text, JSON, or Binary format with Postman

Successful response from server after sending mock event!

Once you send your mock event, Postman will emit the provided event on your behalf and your server will respond! You can drill into the event response:

Hopefully this enables faster development and testing iterations for your WebSocket projects. It’s a fascinating protocol and the tooling around it is only getting better!

--

--

Kyle Krupp

Full-Stack Software Engineer @ Liberty Mutual Insurance, GRM US — INNOVATION ENABLEMENT TECH