APIHelper Gem Version Build Status Docs Status

Helpers for creating standard RESTful API for Rails or Grape with Active Record.


Add this line to your application's Gemfile:

gem 'api_helper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install api_helper

API Standards

Let clients choose the fields they wanted to be returned with the "fields" query parameter, making their API calls optimizable to gain efficiency and speed.
Clients can use the "include" query parameter to enable inclusion of related items - for instance, get the author's data along with a post.
Paginate the results of a resource collection, client can get a specific page with the "page" query parameter and set a custom page size with the "per_page" query parameter.
Client can set custom sorting with the "sort" query parameter while getting a resource collection.
Enables clients to filter through a resource collection with their fields.
Let Client execute operations on multiple resources with a single request.


Ruby on Rails (Action Pack)

Include each helper concern you need in an ActionController::Base:

PostsController < ApplicationController
  include APIHelpers::Filterable
  include APIHelpers::Paginatable
  include APIHelpers::Sortable

  # ...


Further usage of each helper can be found in the docs.


Set the helpers you need in an Grape::API:

class PostsAPI < Grape::API
  helpers APIHelpers::Filterable
  helpers APIHelpers::Paginatable
  helpers APIHelpers::Sortable

  # ...


Further usage of each helper can be found in the docs.


After checking out the repo, run bin/setup to install dependencies. Then, run appraisal rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


Bug reports and pull requests are welcome on GitHub at https://github.com/Neson/api_helper.