Rails Api Template is a boilerplate project for JSON RESTful APIs. It follows the community best practices in terms of standards, security and maintainability, integrating a variety of testing and code quality tools. It's based on Rails 6 and Ruby 2.7.2.
Finally, it contains a plug an play Administration console (thanks to ActiveAdmin).
This template comes with:
- Schema
- Users table
- Admin users table
- Endpoints
- Sign up with user credentials
- Sign in with user credentials
- Sign out
- Reset password
- Get and update user profile
- Administration panel for users
- Rspec tests
- Code quality tools
- API documentation following https://apiblueprint.org/
- Clone this repo
- Install PostgreSQL in case you don't have it
- Run bootstrap.sh with the name of your your project like
./bootstrap.sh my_awesome_project
- Create your
database.yml
andapplication.yml
file bundle install
- Generate a secret key with
rake secret
and paste this value into theapplication.yml
. rake db:create
rake db:migrate
rspec
and make sure all tests passrails s
- You can now try your REST services!
- ActiveAdmin for easy administration
- ActiveModelSerializer for easy administration
- Annotate for doc the schema in the classes
- ApiPie for Api documentation
- Better Errors for a better error page
- Brakeman for static analysis security
- Bullet help to kill N+1
- Byebug for debugging
- Capistrano for deployment
- Capistrano::Rails::Console for rails console from server
- Devise for basic auth
- Devise Token Auth for api auth
- Factory Bot for testing data
- Faker for generating test data
- Figaro for handling environment variables
- Letter Opener for previewing a mail in the browser
- Oj for optimized json
- Puma for the server
- Rails Best Practices for rails linting
- Reek for ruby linting
- RSpec for testing
- Rubocop for ruby linting
- Shoulda Matchers adds other testing matchers
- Simplecov for code coverage
- Webmock for stubbing http requests
- Set your mail sender in
config/initializers/devise.rb
- Config your timezone accordingly in
application.rb
.
http://localhost:3000/api_docs
- Username:
developer
- Password:
password
- You can update credentials in
config/initializers/apipie.rb
With rake code_analysis
you can run the code analysis tool, you can omit rules with:
- Rubocop Edit
.rubocop.yml
- Reek Edit
config.reek
- Rails Best Practices Edit
config/rails_best_practices.yml
- Brakeman Run
brakeman -I
to generateconfig/brakeman.ignore
- Bullet You can add exceptions to a bullet initializer or in the controller
- After adding the project to CC, go to
Repo Settings
- On the
Test Coverage
tab, copy theTest Reporter ID
- Replace the current value of
CC_TEST_REPORTER_ID
on theconfig.yml file (.circleci/config.yml)
with the one you copied from CC
You can use CODEOWNERS file to define individuals or teams that are responsible for code in the repository.
Code owners are automatically requested for review when someone opens a pull request that modifies code that they own.
Rails Api Template is forked from Rootstrap and updated with respect to our requirements by me Muhammad Soban Akram