An open API service indexing awesome lists of open source software.

https://github.com/zetavg/api_helper

Helpers for creating standard RESTful API for Rails or Grape with Active Record.
https://github.com/zetavg/api_helper

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# APIHelper [![Gem Version](https://badge.fury.io/rb/api_helper.svg)](http://badge.fury.io/rb/api_helper) [![Build Status](https://travis-ci.org/Neson/api_helper.svg?branch=master)](https://travis-ci.org/Neson/api_helper) [![Coverage Status](https://coveralls.io/repos/Neson/api_helper/badge.svg?branch=master)](https://coveralls.io/r/Neson/api_helper?branch=master) [![Docs Status](https://inch-ci.org/github/Neson/api_helper.svg?branch=master)](https://inch-ci.org/github/Neson/api_helper)

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:

```ruby
gem 'api_helper'
```

And then execute:

$ bundle

## Usage

### Ruby on Rails (Action Pack)

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

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

# ...

end
```

Further usage of each helper can be found in the [docs](http://www.rubydoc.info/github/zetavg/api_helper/master/APIHelper).

### Grape

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

```ruby
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](http://www.rubydoc.info/github/zetavg/api_helper/master/APIHelper).

## 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](https://rubygems.org).

## Contributing

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