Sunday, August 2, 2020

Websockets vs REST API

The idea behind a socket, is that it is a “port” through which data goes in and out of. Much like a real trading port for data, the socket itself is like the dock, it’s where exchanges are happening from the application standpoint. The socket itself is abstract and low level, and staying with the metaphor, many different ships, trains, and equipment can use it. We can call all of these Protocols.

On the Internet there are hundreds of protocols, but a few stand out as the most common, like HTTP, FTP, SMTP, POP3, etc. and lower level transport protocols like TCP and UDP. In essence, Protocols determine how to interpret the data going to and from the socket and the machines that are communicating with each other.


What are WebSockets?

WebSockets are really just an extension of the socket idea. While HTTP was invented for the World Wide Web, and has been used by browsers since then, it had limitations. It was a particular protocol that worked in a particular way, and wasn’t well suited for every need. In particular was how HTTP handled connections. Whenever you made a request, say to download html, or an image, a port/socket was opened, data was transferred, and then it was closed.

The opening and closing creates overhead, and for certain applications, especially those that want rapid responses or real time interactions or display streams of data, this just doesn’t work.

No comments:

Post a Comment