Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/undr/river
River renders JSON to a stream using the batch iteration
https://github.com/undr/river
coding-challenge ruby
Last synced: about 1 month ago
JSON representation
River renders JSON to a stream using the batch iteration
- Host: GitHub
- URL: https://github.com/undr/river
- Owner: undr
- License: mit
- Created: 2013-08-27T10:38:07.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-27T19:13:11.000Z (over 11 years ago)
- Last Synced: 2023-03-10T20:33:20.887Z (almost 2 years ago)
- Topics: coding-challenge, ruby
- Language: Ruby
- Homepage:
- Size: 133 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# River
River renders JSON to a stream using the batch iteration
## Installation
Add this line to your application's Gemfile:
gem 'river', github: 'undr/river'
And then execute:
$ bundle
## Usage
class HomeController < ApplicationController
before_filter :find_pagesdef stream
stream_json_in_batches(@pages, batch_size: 2)
enddef chunked_stream
stream_json_in_batches(@pages, chunked: true, batch_size: 2)
endprivate
def find_pages
@pages = Page.where('id < 10')
end
endOr:
class HomeController < ApplicationController
respond_to :jsonbefore_filter :find_pages
def stream
respond_with(@pages, in_batches: { batch_size: 2 })
enddef chunked_stream
respond_with(@pages, in_batches: { chunked: true, batch_size: 2 })
endprivate
def find_pages
@pages = Page.where('id < 10')
end
endChunked JSON:
undr$ telnet localhost 3000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /chunked_stream
33f
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":1,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":2,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]
33f
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":3,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":4,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]
33f
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":5,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":6,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]
33f
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":7,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":8,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]
1a0
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":9,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]
0Not chunked JSON:
undr$ telnet localhost 3000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /stream
[{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":1,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":2,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":3,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":4,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":5,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":6,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":7,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":8,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"},{"body":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin risus. Praesent lectus.
","created_at":"2013-08-26T20:11:11Z","id":9,"title":"Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit","updated_at":"2013-08-26T20:11:11Z"}]## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request