Disclaimer: What I am about to show you is NOT REST.
Today I’ve been playing around with using DNode for WebSockets/long polling in Node. It layers on top of SocketIo so it can degrade nicely to long polling etc. The other nice thing about it is it does not depend on native modules as is the case with Now.js. This is yet another point in time issue as the native module story is in progress.
Here’s a simple hello world using Express so you can see how it works.
Here is the server:
And here is the client:
And here is the result using WebSockets in Chrome
Notice in the app I define a sayHello function which is called from the client. The client in this case also sends a callback which the server can use to talk back. This is kind of cool as it on the client it can have access to context in the original closure where the initial call was made. The server can also directly use the client object to invoke functions defined on the client such as sayAnotherMessage below.
To grab it, npm install dnode.