New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

api_pagination_headers

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api_pagination_headers

  • 2.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

api_pagination_headers Build Status Dependency Status

Adds pagination info to a Link response header.

This technique is considered to be a best practice for REST APIs and is currently used by GitHub. The gem also adds the total number of records into a Total-Count header.

Support for rails-api is built in.

Example

Link: <http://example.com/posts?page=2&per_page=10>; rel="next", <http://example.com/posts?page=2&per_page=10>; rel="last"
Total-Count: 11

Requirements

Install

Include in your Gemfile:

gem 'api_pagination_headers'

Usage

class PostsController < ApplicationController
  after_action only: [:index] { set_pagination_headers(:posts) }

  def index
    @posts = Post.all.paginate(per_page: params[:per_page], page: params[:page])
    respond_with @posts
  end
end

Config

ApiPaginationHeaders.configure do |config|
  # Change total count header title (default: 'Total-Count')
  config.total_count_header = 'X-Total-Count'
  
  # Force HTTPS (default: false)
  config.force_https = true
end

License

MIT © Richard Käll

FAQs

Package last updated on 18 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc