Skip to content

Instantly share code, notes, and snippets.

@teamon
Created August 12, 2015 15:48
Show Gist options
  • Save teamon/f87f9a96603018c9568c to your computer and use it in GitHub Desktop.
Save teamon/f87f9a96603018c9568c to your computer and use it in GitHub Desktop.
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
source "https://rubygems.org"
gem "grape"
gem "kaminari"
gem "grape-kaminari", "~> 0.1.8"
⌘ ~/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