DEV Community

What do you use to create REST APIs with WebSockets?

When creating REST APIs I use the Django Rest Framework, as I love Django and Python.

But when it comes to WebSockets, it feels too complicated to what it should be an easier task.

What language and framework do you love to use to create REST APIs with WebSockets?

Top comments (16)

yaser profile image
Yaser Al-Najjar • Edited

I tend to avoid websockets all together.


They're unreliable & hard to scale, the connection might drop, and you might find yourself doing polling for the sake of reliability...

Before going websockets, I would say please read this:

diek profile image

As you say, websockets and unreliable and hard to scale, very much... but they are very useful and helps to make tools that enhance the UX.
Answering to @DavidMM, i must say that websockets and an api rest are not compatibles in the same scenario, api rest are meant to be an question & answer architecture. If you want to have websockets, you need to have a server with a software that allows them, Node is an example.
Anyway, you can have an api rest working on some machine, and a server side that gives you the websocket feature for your needs, they can be on different machines, same machine and different software or the same software. For example, i have made an api rest in node+express that at the same times allows websockets that sends and receives messages.

mostafaahamidmanon profile image
Mostafa A. Hamid

Maybe he cannot study it... :)

krusenas profile image

If you are familiar with Go, then this package is really great - :)

On the backend side I usually connect websocket to a NATS channel for that customer's resource, this way it's easy to scale websocket clients horizontally without much effort. WebSockets are great for UI updates, a lot better than polling.

Check out SSE as well:

davidmm1707 profile image
David MMπŸ‘¨πŸ»β€πŸ’»

I work with Python and Javascript, so I wanted to learn a backend language strongly typed.

And everything points that I should learn Go. Thanks for the link and for pushing me a step more towards Go.

jackmichaud profile image
Jack Michaud

I tended to err away from WebSockets until I tried making a socket server with AWS API Gateways.

A high level overview: a WebSocket connection triggers a lambda where you log a connection ID into a database. The connection ID can be used to send data back to that connection through other lambdas. The disconnecting the WebSocket triggers another lambda where you can remove the connection ID.

I like this solution because it's highly scalable and fits into my work's infrastructure well. I know AWS isn't for everyone!

oxygen profile image
oxygen • Edited

All APIs are fundamentally RPC. For example, if you would use JSON-RPC over HTTP it could still be considered REST as long as you follow REST principles (the JSON-RPC would be just be a standard way to represent all requests and all responses).

Here’s a library that allows you to export APIs over both HTTP and WebSocket on the same server

michelemauro profile image

WebSockets are made to be real-time, and bidirectional. REST is (usually) unidirectional, from the client to the server.

You better isolate on websocket only the use cases that really need those features i.e. server-initiated messages, real-time interaction, presence notification and such.

The two programming models of traditional frameworks and websocket ones (request/response vs. message passing) are different for clear and important reasons; there is little use in trying to avoid the "complications" in websocket use (i.e. everything async) because they are essential characteristics of the medium.

jamesthomson profile image
James Thomson

I’ve recently discovered AdonisJS. Might be worth looking at.

wobsoriano profile image

I am using Adonis for a year now side-by-side with Laravel for php projects.

jamesthomson profile image
James Thomson

I've also come from Laravel, the familiarity in concepts has made picking up Adonis quite smooth - and working in one language for both FE and BE is great.

davidmm1707 profile image
David MMπŸ‘¨πŸ»β€πŸ’»

I have read something about it but I never went deeper (I thought it was another Frontline Framework).


attacomsian profile image

Check out You can use it in Node.js/Express.

tomerl101 profile image

I guess you can use it for any real time service , for example getting live notifications from server

jobm profile image
Job Matheka
bonanhel profile image

Give a try to nginx nchan :)