WebSockets allow for bidirectional communication between a client and server by establishing a persistent connection. They provide advantages over traditional AJAX requests by eliminating HTTP overhead, enabling full-duplex connections where the server can push updates to the client, and allowing for low latency binary data transfer. While WebSockets have disadvantages like lack of caching and compatibility issues on older browsers, they can be used to build real-time REST APIs through protocols like WAMP which defines a simple publish-subscribe messaging system.