API pagination for all collections using Link header
This commit is contained in:
parent
8d7fc5da6c
commit
b13e7dda1f
13 changed files with 123 additions and 63 deletions
|
@ -1,4 +1,7 @@
|
|||
class ApiController < ApplicationController
|
||||
DEFAULT_STATUSES_LIMIT = 20
|
||||
DEFAULT_ACCOUNTS_LIMIT = 40
|
||||
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
@ -54,6 +57,13 @@ class ApiController < ApplicationController
|
|||
response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
||||
end
|
||||
|
||||
def set_pagination_headers(next_path = nil, prev_path = nil)
|
||||
links = []
|
||||
links << [next_path, [['rel', 'next']]] if next_path
|
||||
links << [prev_path, [['rel', 'prev']]] if prev_path
|
||||
response.headers['Link'] = LinkHeader.new(links)
|
||||
end
|
||||
|
||||
def current_resource_owner
|
||||
User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue