(I'm not familiar to RESTFul, please correct me if my concept is wrong)
In RESTFul architecture, we map every action to an URL. If I click "post a article", may it's actually URL http://example.com/
and some data action=post&content=blahblah
.
If I want to post, but not refresh the whole web page, I can use javascript's XMLHTTPRequest. I post it and then get it's content and insert it to a div in my page. These action is all asynchronous.
Then I know there is something named WebSocket
and it's wrapper socket.io
. It use "message" to communicate between client and server. When I click "post" the client just call socket.send(data)
and wait for server's client.send(data)
. It's magical. But how about URL?
It's possible to use the two model both without repeating myself? In other word, every action has it's URL, and some of them can interact with user real-timely(by socket.io?)
Moreover, should I do this? In a very interactive web program(ex. games), the RESTFul is still meaningful?
http://example.com/product/create
, then when the "post" is complete, your web service will return some form of JSON or XML to tell whether or not the post was successful. I really don't think you need to use sockets as you're describing.POST
request to/products/
socket.send(data)
is missing a lot of the picture. To make the data transfer useful, you still need routing. Just with JSON instead of urls.socket.send({ post:'product/create', . . . })