Is ReST over websockets possible?

REST is an architectural style that does not impose a protocol. So yes, you can do REST with Web Sockets, REST with HTTP and REST with FTP if you like.

The main reason to use HTTP is that it is easy and fairly simple to communicate with any component or programming language via HTTP and also because HTTP supports distributed environments with multiple intermediaries: proxies, firewalls...; So you can deploy your service on any topology and anyone will be able to access it.

My rant: If you are a RESTliban and Roy Fielding’s dissertation is the source of truth, verbs are never acknowledged as part of the semantic. URIs are the semantic. The usage of different verbs for different actions has been an elegant evolution of REST over HTTP, but not part of the "truth". You can check the scenario of rest over HTTP evaluated by Roy in chapter six of his dissertation. No mention to verbs. And notice it is an evaluation scenario, not the specification.

TLDR;

If you need realtime two way communications via the internet and the client is a web browser, the best choice is Web Sockets. You could then implement an application level protocol on top of web sockets to implement a RESTful Web Service.


Yes. You can use REST over WebSocket with library like SwaggerSocket.


Why would you want to build a REST API on top of socket? IMHO the benefit of a REST API is to leverage standard HTTP protocol possibilities like stateless requests, semantic verbs like GET, DELETE to build an API that can be easily understood by (client) developers. Since sockets do not offer HTTP verbs and so on, you would build some kind of HTTP layer for sockets which is IMHO not reasonable.

In case you would really build such a thing, I'd recommend to use the HTTP protocol as a blueprint and implement the socket protocol like HTTP.


REST architectural style mostly presumes 2 entities viz. client and server.

As we move more towards real time web and development of reactive systems WebSocket would prominently start replacing usage of REST API's.

WS allows data push and pull which dismisses the concept of server and client.

STOMP,AMQP ,XMPP can be used as messaging protocols.

The data itself maybe JSON or Google protocol buffers or maybe Apache Avro.

WebSockets is not tied to web servers but can be developed in stand alone apps like mobile apps or desktop apps too.