Skip to content
/ riff Public

Riff enables you to build ruby restful apis in record time!

License

Notifications You must be signed in to change notification settings

tomlobato/riff

Repository files navigation

Riff

Riff is a ruby gem that permits you to quickly build a Restful API in ruby projects that is using Roda and Sequel ORM.

Installation

Add this line to your application's Gemfile:

gem "riff", :git => "git://github.com/tomlobato/riff.git"

And then execute:

bundle install

Features

  • 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

TODO

  • 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

Usage

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...

  1. 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
  1. 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).

  2. 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.

Running tests

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

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Riff project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Acknowledgements

Riff runs on top of:

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.

About

Riff enables you to build ruby restful apis in record time!

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published