Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prx/hal_api-rails
rails-dependent gem for adding actions to your hal-based api.
https://github.com/prx/hal_api-rails
Last synced: 16 days ago
JSON representation
rails-dependent gem for adding actions to your hal-based api.
- Host: GitHub
- URL: https://github.com/prx/hal_api-rails
- Owner: PRX
- License: mit
- Created: 2015-09-29T16:07:17.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T14:58:58.000Z (7 months ago)
- Last Synced: 2024-06-06T07:02:27.795Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 163 KB
- Stars: 0
- Watchers: 10
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HalApi::Rails
[![Build Status](https://travis-ci.org/PRX/hal_api-rails.svg?branch=master)](https://travis-ci.org/PRX/hal_api-rails)
Welcome to hal_api-rails. This is a binding between the responders /
roar / roar-rails gems and the the PRX HAL api.## Installation
Add this line to your application's Gemfile:
```ruby
gem 'hal_api-rails'
```Then add a gem for paging through ActiveRecord result sets:
```ruby
gem 'kaminari'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install hal_api-rails
## Usage
This gem provides a number of additions to the `roar` gem HAL support.
There are several parts of it that need to be used in your apps:
1) Add to your API controllers:
```ruby
require 'hal_api/rails'class Api::BaseController < ApplicationController
include HalApi::Controller
...
end
```2) Add to your `ActiveRecord` models used in your API (perhaps in a base model class):
```ruby
class BaseModel < ActiveRecord::Base
self.abstract_class = trueinclude RepresentedModel
end
```3) Use the base representer, define your own CURIEs:
```ruby
class Api::BaseRepresenter < HalApi::Representer
curies(:prx) do
[{
name: :foo,
href: "http://foo.bar/relation/{rel}",
templated: true
}]
enddef index_url_params
'{?page,per,zoom}'
enddef show_url_params
'{?zoom}'
end
end
```## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` 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/[USERNAME]/hal_api-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).