APIHelper Gem Version Build Status Coverage Status Docs Status

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

API Standards

Fieldsettable
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.
Includable
Clients can use the include query parameter to enable inclusion of related items - for instance, get the author's data along with a post.
Paginatable
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.
Sortable
Client can set custom sorting with the sort query parameter while getting a resource collection.
Filterable
Enables clients to filter through a resource collection with their fields with the filter query parameter.
Multigettable
Let Client execute operations on multiple resources with a single request.

Installation

Add this line to your application's Gemfile:

gem 'api_helper'

And then execute:

$ bundle

Usage

Ruby on Rails (Action Pack)

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

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

  # ...

end

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

Grape

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

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

  # ...

end

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

Development

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.

Contributing

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