This is a basic Rails 4 application with Doorkeeper, Grape & Swagger for getting to API building quickly.
You can view the live app and the Swagger-ui documentation.
This app is ready to deploy to Heroku
First bundle install
and rake db:setup
Run rake start
to get the server running locally. It runs at http://localhost:3001
You will want to change config/initializers/secret_token.rb and export DEVISE_SECRET_KEY
(see config/initializers/devise.rb).
You will also probably want to delete the imaginary item class and serializer, which are included for demonstration in the me/items endpoint.
This app includes omniauth-bike-index. For Bike Index login to work, export environment variables BIKEINDEX_APP_ID
and BIKEINDEX_APP_SECRET
. You'll need a Bike Index app, which you can create at BikeIndex.org/oauth/applications/new.
Bike Index uses a similar grape, Swagger, doorkeeper setup—this is an example of creating an OmniAuth strategy for doorkeeper.
Grape is mounted in app/controllers/api, as described in the excellent Introduction to building APIs with Grape by Monterail, and part 2 of the series.
There are are other posts in the series which are worth reading, particularly OAuth Implicit Grant with Grape, Doorkeeper and AngularJS.
There is also a Railscast on doorkeeper.
Important things in the Gemfile:
- Doorkeeper (OAuth providing)
- grape (API building)
- wine_bouncer (Doorkeeper and Grape)
- grape-swagger (automatically generates Swagger docs for the auto documentation)
- Devise (users)
Also important, but maybe not as necessary to know about:
- rails_swagger-ui (how we get swagger-ui)
- Puma (the web server)
- api-pagination
- grape-active_model_serializers
- CORS
- foreman (in development to manage processes)
- Haml
- dotenv-rails (load environmental variables - .env is in .gitignore, so it isn't committed)
- Bootstrap
- Postgres
If you want to change the name of the app, swap out:
GrapeDoorkeeper
in config/application.rbgrape-doorkeeper
in config/database.yml (multiple instances)grape-doorkeeper
in config/initializers/session_store.rb
Rspec and guard - run bundle exec guard
to watch your spec files for changes and rerun tests for those files.
There is a spec for the api/v1/me
API route and for the swagger docs to help get you started.