Is it possible to implement websockets with a REST API (decoupled front end)?

Let’s say I have a web application where the front end is decoupled from the backend. The server exchanges only non-UI data between the client and the server, mainly in the form of JSON. The backend would be a REST API in this case.

REST API’s are stateless. However, what if I wanted to implement websockets, where the server can push data to the client, especially to a specific user? Would this still be possible?

You would normally have another endpoint, REST implenetations generally use HTTP, and Websockets are not HTTP. It’s an architectural style rather than a protocol, so theoretically you could have a WS REST API but :man_shrugging:. Anyway, one approach is to send notifications of events over the sockets, and they then trigger an HTTP call, maybe the data can then be sent back via a socket.

1 Like