Sha256: f2ce4417f33a987eee05b2844bd47b49d12bbcf47c081bd75768b5f3e785d4b8

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

#api_pagination_headers [![Build Status](https://travis-ci.org/richardkall/api_pagination_headers.svg)](http://travis-ci.org/richardkall/api_pagination_headers) [![Dependency Status](https://gemnasium.com/richardkall/api_pagination_headers.png)](https://gemnasium.com/richardkall/api_pagination_headers)

api_pagination_headers is a gem that adds pagination info to a `Link` response header. This is considered to be the [best practice](http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#pagination) for REST APIs and is currently used by [GitHub](http://developer.github.com/v3/#pagination). It also adds the total number of records into a `X-Total-Count` header.

Example:

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

##Installation

Include in your Gemfile:

```
gem 'api_pagination_headers'
```

Depending on [will_paginate](https://github.com/mislav/will_paginate) at the moment. Support for [rails-api](https://github.com/rails-api/rails-api) is built in.

##Usage

In the controller:

```
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
```

##License
Copyright © 2014 [Richard Käll](http://richardkall.se). Licensed under the MIT license.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api_pagination_headers-1.1.2 README.md