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.
- Host: GitHub
- URL: https://github.com/zetavg/api_helper
- Owner: zetavg
- Created: 2015-06-12T11:15:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-17T01:18:10.000Z (over 1 year ago)
- Last Synced: 2025-04-10T12:10:25.178Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 52.7 KB
- Stars: 10
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# APIHelper [](http://badge.fury.io/rb/api_helper) [](https://travis-ci.org/Neson/api_helper) [](https://coveralls.io/r/Neson/api_helper?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.