All Projects → IcaliaLabs → Pager Api

IcaliaLabs / Pager Api

Licence: mit
Easy API pagination for Rails

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Pager Api

Flexirest
Flexirest - The really flexible REST API client for Ruby
Stars: ✭ 188 (+118.6%)
Mutual labels:  api, json, rails, gem
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (+16.28%)
Mutual labels:  api, rails, gem
Api Pagination
📄 Link header pagination for Rails and Grape APIs.
Stars: ✭ 641 (+645.35%)
Mutual labels:  api, rails, pagination
Sabisu Rails
Simple and powerful engine for exploring your Rails api application
Stars: ✭ 129 (+50%)
Mutual labels:  api, json, rails
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (+122.09%)
Mutual labels:  api, json, rails
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+181.4%)
Mutual labels:  api, json, rails
Jsonapi.rb
Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
Stars: ✭ 116 (+34.88%)
Mutual labels:  api, rails, pagination
Datoji
A tiny JSON storage service. Create, Read, Update, Delete and Search JSON data.
Stars: ✭ 222 (+158.14%)
Mutual labels:  api, json, rails
Acts as api
makes creating API responses in Rails easy and fun
Stars: ✭ 506 (+488.37%)
Mutual labels:  api, json, rails
Jsonapi parameters
Rails-way to consume JSON:API input
Stars: ✭ 50 (-41.86%)
Mutual labels:  api, json, rails
Sirvy
🔗 Kirby Services API
Stars: ✭ 59 (-31.4%)
Mutual labels:  api, json
Http Prompt
An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
Stars: ✭ 8,329 (+9584.88%)
Mutual labels:  api, json
Jsonapi
[Bolt Extension] JSON API for Bolt CMS
Stars: ✭ 55 (-36.05%)
Mutual labels:  api, json
Easyjson
Provides an unified JSON access API, you can adapter any JSON library to Gson, Jackson, FastJson with easyjson。 提供了一个JSON门面库,就像slf4j一样。easyjson本身不做json的操作,完全依赖于底层实现库。可以直接使用Easyjson的API,底层的JSON库随时可切换。也可以使用其中某个json的API,然后通过easyjson适配给其他的json库
Stars: ✭ 54 (-37.21%)
Mutual labels:  api, json
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+1213.95%)
Mutual labels:  api, json
Gophergameserver
🏆 Feature packed, easy-to-use game server API for Go back-ends and Javascript clients. Tutorials and examples included!
Stars: ✭ 61 (-29.07%)
Mutual labels:  api, json
Rails 5 api tutorial
Building the Perfect Rails 5 API Only App & Documenting Rails-based REST API using Swagger UI
Stars: ✭ 66 (-23.26%)
Mutual labels:  api, rails
Utils
🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
Stars: ✭ 1,158 (+1246.51%)
Mutual labels:  json, pagination
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-17.44%)
Mutual labels:  api, json
Lofocats ui
LofoCats UI is a simple web application consuming the LofoCats API, built with Ruby on Rails 🐱
Stars: ✭ 54 (-37.21%)
Mutual labels:  api, rails

Code Climate Test Coverage Issue Count

Pager API

Pager

API Pagination done right. Pager API is a library to help you add meta information and the adequate header with pagination information based on the JSON API standard for your Rails app.

Table of contents

Quick Start

pager_api depends on Pagy, Kaminari, WillPaginate to handle pagination. You need to add one of these gems to your Gemfile before the pager_api gem:

# gem 'will_paginate'
# gem 'kaminari'
# gem 'pagy'
gem 'pager_api'

And then execute:

% bundle

Configuration

This step is totally optional

The gem comes with an installer for you to configure it, for example to switch between pagination handlers or whether or not to include the Link header or meta information. To install it you just need to run:

% rails g pager_api:install

This will create a file under the initializers directory called pager_api.rb. You can easily configure it there to meet your needs.

By default pager_api uses Pagy. Configure the pager_api.rb initializer in order to use WillPaginate or Kaminari.

We highly recommend you use Active Model Serializers for rendering your JSON responses

A note on Active Model Serializers 0.10

Currently the pager-api gem needs some configuration to work nice with Active Model Serializers, just add a file under config/initializers on your rails project:

% touch config/initializers/active_model_serializers.rb

And a this line:

ActiveModelSerializers.config.adapter = :json

Or even

ActiveModelSerializers.config.adapter = :json_api

Usage

In the controller where you are providing a paginated collection, you may have something like this:

class UsersController < ApplicationController
  def index
    users = User.page(params[:page]).per(15)

    render json: users,
           meta: {
             pagination: {
               per_page: 15,
               total_pages: 10,
               total_objects: 150
             }
           }
  end
end

With pager_api it is really easy to achieve the above by:

class UsersController < ApplicationController
  def index
    # You can have any scope for the User class in this case
    # You can even send the paginated collection
    paginate User.unscoped, per_page: 15
  end
end

This will output a json object like:

{
    "users": [
    	...
    ],
    "meta": {
        "pagination": {
            "per_page": 15,
            "total_pages": 1,
            "total_objects": 15,
            "links": {
                "first": "/api/users?page=1",
                "last": "/api/users?page=1"
            }
        }
    }
}

As you can see, the pagination metadata also includes the links information for the first and last page, but it will also create the next and the prev keys when necessary.

By default it will also include a Link header with the following information:

# Link: <http://example.com/api/v1/users?page="2">; rel="next",
# <http://example.com/api/v1/users?page="5">; rel="last",
# <http://example.com/api/v1/users?page="1">; rel="first",
# <http://example.com/api/v1/users?page="1">; rel="prev",

The header will be created with the corresponding first, last, prev and next links.

Bug tracker & feature request

Have a bug or a feature request? Please open a new issue. Before opening any issue, please search for existing issues.

Contributing

Please submit all pull requests against a separate branch. Although pager_api does not have tests yet, be a nice guy and add some for your feature. We'll be working hard to add them too.

In case you are wondering what to attack, we have a milestone with the version to work, some fixes and refactors. Feel free to start one.

Thanks!

Heroes

Abraham Kuri

License

Code and documentation copyright 2015 Icalia Labs. Code released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].