Rails 8 and Ruby 3.4 API Boilerplate application
Setup
Ensure that Ruby 3.4 is installed and active in the environment. You can use a version manager like rbenv
or rvm
to manage Ruby versions. This application is built with Rails 8 and uses MySQL as the database. The code is tested with MySQL 9.3 but should work with MySQL 8.0 as well.
git clone https://github.com/ngudbhav/rails-api-boilerplate.git
cd rails-api-boilerplate
bin/setup
Features
-
API-only Rails application
-
Global credentials loader with fail-safe (lib/credentials.rb)
-
YJIT enabled for performance (lib/enable_yjit.rb)
-
Common utilities for API responses (controllers/concerns/api_response.rb)
-
Uses Trilogy as the MySQL adapter for better performance
-
Integration with Sentry for error tracking
-
Integration with Discard (successor of Paranoia) for soft deletion
-
Integration with Sidekiq for background job processing
-
Preconfigured with Rubocop
-
Preconfigured with GitHub Actions and Dependabot for CI/CD
-
Unit testing with RSpec
Documentation
Documentation is generated using YARD and can be viewed online at ngudbhav.github.io/rails-api-boilerplate. The documentation is Continuously deployed using GitHub Actions. Check the main.yml for the deployment process. The documentation only builds when the main
branch is updated.
Running the Application
To start the Rails server, run:
rails server
CAUTION
Issue the below command and remove master.key file from the repository.
git rm config/master.key
Rotate the master key immediately and store it securely. The application will not work without it.
It is also recommended to rotate the secret_key_base
in the config/credentials.yml.enc
file.
Setting up Sentry
To set up Sentry, you need to create a Sentry account and obtain a DSN (Data Source Name). Once you have the DSN, add it the application. You can do this by setting the sentry.dsn
in the config/credentials.yml.enc
file:
EDITOR="code --wait" bin/rails credentials:edit