REST and Web Sockets?
I must be missing something here… . I went ahead and looked at Web Sockets since it sounded like a great solution to improve the communication from client to server instead of HTTP. It seems like the WebSockets send API only allows to send either binary data or a text string. And this got me wondering, how the frack do you implement REST over WebSockets in a uniform way?
First and foremost, how do you represent a URI? Second, how do you represent the HTTP methods (GET, PUT, POST, …)? And last, how do you represent HTTP uri parameters and headers? It seems like maybe a solution for this is to built some sort of schema into the content that goes into that text string. Something like a JSON string that has a “uri” field, and “params” and so on. But thats annoying, since with HTTP, you can create very simple gateways that simply use the headers or parameters without needing to parse the body…
Am I missing something here? Why doesn’t WebSockets send method have the notion of a URI and headers (which can be passed in optimized binary format for fast parsing)? It seems like REST has taken a beating with WebSockets…
On top of that, it seems like (and correct me if I’m wrong here) you register a listener that accepts all responses. If we want to simulate an async request response scenario, the client needs to create a unique request id, and the server must send it back so the client will correlate a response to a specific request.
If all the above holds, it means that people will reinvent what both REST and async request response communication does and probably not in a uniform manner. Do we now need a REST over WebSockets specification?
p.s. I understand the benefits of WebSockets for comet style, long polling HTTP requests, just want to use it for typical async RESTful request response type instead of HTTP.
About Shay Banon
Shay is the founder of the Compass open source project, a unique solution enabling search capabilities into any application model. He started working on mission critical real time C/C++ systems, later moving to Java (and never looked back). Within the Java world, Shay has worked on a propriety implementation of a distributed rule engine(RETE) server, your typical Java based web projects, and messaging based projects within the financial industry. Currently, Shay is a System Architect at GigaSpaces, GigaSpaces provides a single platform for end-to-end scalability of high performance and stateful distributed applications. GigaSpaces’ unique approach enables developers to Write their business logic Once and then seamlessly Scale out the application linearly Anywhere.
More About Shay »NFJS, the Magazine
2011-09-01 00:00:00.0 Issue Now AvailableBuild Your Own Technology Radar
by Neal FordProgramming with Scala Traits, Part Two
by Venkat SubramaniamMVC Meet Javascript, Javascript Meet MVC
by Brian Sam-BoddenThe Art of Groovy Command Expressions in DSLs
by Hamlet D`Arcy