Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to define custom headers response #706

Closed
nexxus-vi opened this issue Feb 11, 2021 · 3 comments
Closed

Add possibility to define custom headers response #706

nexxus-vi opened this issue Feb 11, 2021 · 3 comments

Comments

@nexxus-vi
Copy link

nexxus-vi commented Feb 11, 2021

Hi, i'm using pagy in an API Only project to paginate model's index. This gem provides additional header in response, such as

Link - <http://localhost:3000/api/v1/accounts?page=1>; rel="first", <http://localhost:3000/api/v1/accounts?page=1>; rel="last"

Current-Page - 1

Page-Items - 2

Now i can add headers for request like this:

header 'Authorization', 'Bearer [your_access_token]', required: true
header 'Content-Type', 'application/json', required: true
header 'Accept', 'application/json', required: true

but how about headers for response?

@davidwessman
Copy link
Contributor

@PanosCodes do you think it would make sense to add this to the returns-DSL now?
I am also in need of it for this exact use-case.
Would also be great if there would be some way to add this in a reusable pattern.

returns(array_of: Company::ApiDescription, headers: pagy_headers)
def index
end

where we could implement pagy_headers just like a hash or even a param_group.

def pagy_headers
  [
    { key: "Link", description: "Relative links according to RFC..:"},
    { key: "Current-Page", description: "The current page in the pagination")},
    ...
  ]
end

@PanosCodes
Copy link
Contributor

PanosCodes commented Apr 4, 2024

Sure, what do to you think about #924

@mathieujobin
Copy link
Collaborator

released in v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants