Riff is a ruby gem that permits you to quickly build a Restful API in ruby projects that is using Roda and Sequel ORM.
Add this line to your application's Gemfile:
gem "riff", :git => "git://github.com/tomlobato/riff.git"
And then execute:
bundle install
- Auth (access_token/refresh_token)
- Authorization
- Parameters checking
- Implementation of the default CRUD actions (but can be overwritten)
- Custom actions (aka restful custom methods, like
POST /actions/users/123:custom_method
) - Pagination/Ordering
- Request throttling (in the seed/sample_app)
- [tests] Full test coverage
- Rails and Activerecord support
- JSON API support
- Project generator (
riff new my_api
) - Gem docs
- Docs generation for apis created with Riff
- Elasticsearch support
- rake to generate resource customizations from database tables
- [marketing] Open source marketing
Instead to create a roda app from zero, copying the sample riff app is a quick way to have your project up and running.
But if you prefer to plug riff directly in you app...
- In your app.rb file (where you have
class App < Roda ...
), add entries like this to direct your requests to Riff (see the sample riff app).
route do |r|
r.post('session', String) do |action|
Riff.handle_session(r, response, action)
end
r.on('actions') do
Riff.handle_action(r, response)
end
end
-
Create the riff customizations inside your app inside the constant path
Actions::<MY_MODEL>::*
for each model you want to expose in your api (see examples in sample_app/app/riff/actions). -
Configure Riff minimally setting the user class
Riff::Conf.set(:default_auth_user_class, User)
, so riff can handle auth for you. See a example in riff.rb).
See also the sample_app and its specs for help on using Riff.
The automated tests for riff are inside the sample_app:
cd sample_app
mysqladmin create my_app_test
# Then create .env.test based on .env.test.template
# Install and run redis-server in another terminal:
brew install redis # on mac
redis-server # on mac
sudo aptitude install redis-server # on ubuntu/debian
bundle install
RACK_ENV=test bundle exec rake db:migrate
RACK_ENV=test bundle exec rspec
Bug reports and pull requests are welcome on GitHub at https://github.com/tomlobato/riff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Riff project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Riff runs on top of:
- Roda
- Sequel ORM
- ActiveSupport
- dry-validation
- todo_api for the sample app
- Oj
Big thanks to Jeremy Evans for bring to us Roda and Sequel, not mentioning rodauth and tons of other great code.
Big thanks to Mateusz Urbański for bring to us the great project todo_api, used in riff as a seed for the sample app and its auth logic for Riff auth handler.