Rails 5 API starter is a boilerplate which helps you build fast, secure and efficient API for applications. Template based on automatically generated structure of directory and settings which are default delivered by --api switch. Additional to settings are added and initially configure useful Gems, which are often used in Rails stack application.
- omniauth
- devise
- devise_token_auth
- cancancan
- jbuilder
- rspec-api-documentation
- yard
- rspec-rails
- json_spec
- factory-girl
- faker
- simpleconv
- rack-attacker
- rack-timeout
- readthis
- hiredis
- spirng
- better_errors
- awesome_print
- rails_panel
- pry-byebug
- sidekiq
- prmd
Boilerplate based on Docker container. To start using them, first, we have to make sure that Docker Engine and Docker compose tool are installed.
- Compose 1.6.0+
- Docker Engine 1.10.0+
$ git [email protected]:Hawatel/rails5-api-starter.git
$ docker-compose build
$ docker-compose run web bundle
$ docker-compose run web rails db:create
$ docker-compose run web rails db:migrate
To start the server you only need to run the following magic command:
$ docker-compose up
It is only necessary from the perspective of the framework to change the application name in config/application.rb file.
...
module HawatelApi5Starterkit # CHANGE HERE
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
# Use Rack Attack
config.middleware.use Rack::Attack
end
end
To avoid install gems from scratch in each time when Gemfile will be updated, boilerplate has implemented persistent, cross-container dedicated volume for gems. Now in case when new entry to Gemfile is added, just run below command to update state:
$ docker-compose run web bundle
RailsPanel is a Chrome extension for Rails development that will end your tailing of development.log. Have all information about your Rails app requests right there in the Developer Tools panel. To use this you will need to install Chrome extension from this link .
Running your test suite is done quite easily. You have to just set RAILS_ENV to test and execute rspec command the same way you would run your tests locally:
$ docker-compose run -e "RAILS_ENV=test" rspec
In case when you need initialize or migrate database in test env call rails db:create or db:migrate:
$ docker-compose run -e "RAILS_ENV=test" web rails db:create
$ docker-compose run -e "RAILS_ENV=test" web rails db:migrate
$ docker-compose run -e "RAILS_ENV=test" web rake docs:generate
The Starter Kit is available as open source under the terms of the MIT License.
- https://geemus.gitbooks.io/http-api-design/content/en/
- https://labs.omniti.com/labs/jsend
- http://jsonapi.org/
- https://github.com/phatworx/devise_security_extension - Add Devise security extension