Created
August 12, 2015 15:48
-
-
Save teamon/f87f9a96603018c9568c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
Bundler.require | |
class MyApi < Grape::API | |
include Grape::Kaminari | |
paginate | |
get "/defaults" do | |
things = ['a', 'standard', 'array', 'of', 'things', '...'] | |
paginate(Kaminari.paginate_array(things)) | |
end | |
paginate per_page: 13 | |
get "/custom" do | |
things = ['a', 'standard', 'array', 'of', 'things', '...'] | |
paginate(Kaminari.paginate_array(things)) | |
end | |
end | |
run MyApi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "grape" | |
gem "kaminari" | |
gem "grape-kaminari", "~> 0.1.8" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⌘ ~/Desktop/grape-kaminari-test λ curl -i http://localhost:9292/defaults | |
HTTP/1.1 200 OK | |
X-Total: 6 | |
X-Total-Pages: 1 | |
X-Per-Page: 25 | |
X-Page: 1 | |
X-Next-Page: | |
X-Prev-Page: | |
X-Offset: 0 | |
Content-Type: text/plain | |
Content-Length: 49 | |
Server: WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26) | |
Date: Wed, 12 Aug 2015 15:47:00 GMT | |
Connection: Keep-Alive | |
["a", "standard", "array", "of", "things", "..."]% | |
⌘ ~/Desktop/grape-kaminari-test λ curl -i http://localhost:9292/custom | |
HTTP/1.1 200 OK | |
X-Total: 6 | |
X-Total-Pages: 1 | |
X-Per-Page: 13 | |
X-Page: 1 | |
X-Next-Page: | |
X-Prev-Page: | |
X-Offset: 0 | |
Content-Type: text/plain | |
Content-Length: 49 | |
Server: WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26) | |
Date: Wed, 12 Aug 2015 15:47:06 GMT | |
Connection: Keep-Alive | |
["a", "standard", "array", "of", "things", "..."]% | |
⌘ ~/Desktop/grape-kaminari-test λ curl -i "http://localhost:9292/custom?per_page=2" | |
HTTP/1.1 200 OK | |
X-Total: 6 | |
X-Total-Pages: 3 | |
X-Per-Page: 2 | |
X-Page: 1 | |
X-Next-Page: 2 | |
X-Prev-Page: | |
X-Offset: 0 | |
Content-Type: text/plain | |
Content-Length: 17 | |
Server: WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26) | |
Date: Wed, 12 Aug 2015 15:47:30 GMT | |
Connection: Keep-Alive | |
["a", "standard"]% ⌘ ~/Desktop/grape-kaminari-test λ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment