
Building Streaming REST APIs with Ruby - freeatnet
http://intridea.com/blog/2012/5/24/building-streaming-rest-apis-with-ruby
======
sufianrhazi
Unfortunately, this approach will not work for clients using Internet Explorer
(save for IE 10). WebSockets and EventStreams are fairly new, and not
supported across all browsers (both for mobile and non-mobile).

This is why socket.io and its contemporaries have several layers of fallbacks,
even going back to infinite iframe/JSONP polling.

~~~
ericb
Actually, it should work. If you see in the other comments, someone mentioned
that rack-stream uses faye-websocket-ruby, which has multiple fallbacks.

------
ericb
I would suggest anyone implementing this take a look at faye-websocket. It was
recently extracted from a production-quality project named Faye, which uses a
pub-sub broadcast model based on bayeux. The websocket implementation has
numerous fallbacks, and is well-tested. I'm using it in production currently.

<https://github.com/faye/faye-websocket-ruby>

~~~
jollyjerry
faye-websocket-ruby's a great project. rack-stream actually uses it to detect
websocket and eventsource requests, and stream back on those protocols.

~~~
ericb
I had no idea. Cool.

------
lloeki
Is there any information out there regarding streams / chunked responses
within Rails? (I'm not talking about the new template stream facility, but
generating arbitrary data)

I'm currently using enumerators assigned to response_body:

    
    
        self.status_code = 200
        self.response_body = Enumerator.new { |y| ... }
    

I'm hitting a number of problems though, e.g unicorn killing long-lived
workers.

~~~
jollyjerry
Could you link to a fuller gist? Is self referring to an
ActionDispatch::Response object? I plan on improving rails integration with
rack-stream so that you can call `#chunk` from controllers and that will defer
sending a chunk of content.

~~~
lloeki
Here goes: <https://gist.github.com/2823045>

------
royalghost
This is super cool.

