Create an awesome versioned API, secured with OAuth2 and automatically documented.
Set up the rails app and database with
./startto get the server running locally. It runs at http://localhost:3003
Copy .env.sample to
.envand replace the values with your own values.
This app includes omniauth-bike-index. For Bike Index login to work, create a Bike Index app at BikeIndex.org/oauth/applications/new and add the values from
BIKEINDEX_APP_SECRET to the
Bike Index uses a similar grape, Swagger, doorkeeper setup—this is an example of creating an OmniAuth strategy for doorkeeper.
Adding to an existing application
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-assets manages the js for swagger-ui
- Puma (the web server)
- active_model_serializers - uses 0.8 branch of active model serializers, because nothing past 0.8 supports caching
- foreman (in development to manage processes)
- Haml - and Hamlit, which is faster haml
- dotenv-rails (load environmental variables - .env is in .gitignore, so it isn't committed)
If you want to change the name of the app, swap out:
grape-doorkeeperin config/database.yml (multiple instances)
- Do a project wide search of
/grape.doorkeeper/ito catch any lingering ones like api_v1.html.haml
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.