5 ms·
Building Streaming REST APIs with Ruby
- ericb 14y agoI 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 https://github.com/faye/faye-websocket-ruby
- jollyjerry 14y agofaye-websocket-ruby's a great project. rack-stream actually uses it to detect websocket and eventsource requests, and stream back on those protocols.
- ericb 14y agoI had no idea. Cool.
- lloeki 14y agoIs 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.
- deleted 14y ago[deleted]
- jollyjerry 14y agoCould 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 14y agoHere goes: https://gist.github.com/2823045 https://gist.github.com/2823045
- sufianrhazi 14y agoUnfortunately, 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 14y agoActually, it should work. If you see in the other comments, someone mentioned that rack-stream uses faye-websocket-ruby, which has multiple fallbacks.
- royalghost 14y agoThis is super cool.