Home

Awesome

Rails API Template

Github Actions CI Code Climate Test Coverage

Rails API Base 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 7.2 and Ruby 3.3.

Finally, it contains a plug an play Administration console (thanks to ActiveAdmin).

Features

This template comes with:

How to use

  1. Clone this repo
  2. Install PostgreSQL in case you don't have it
  3. Install node. The expected node version is defined in .nvmrc file.
  4. Install yarn. You can run corepack enable to install the required yarn binaries. Corepack is already included in newest node versions.
  5. Run bootstrap.sh with the name of your project like ./bin/bootstrap.sh --name=my_awesome_project.
  6. Run yarn install and yarn build --watch. This bundles the JS assets in the administration site using esbuild.
  7. bundle exec rspec and make sure all tests pass (non-headless mode) or HEADLESS=true bundle exec rspec (headless mode)
  8. Run bin/dev.
  9. You can now try your REST services!

How to use with Docker

  1. Have docker and docker-compose installed (You can check this by doing docker -v and docker-compose -v)
  2. Run bootstrap.sh with the name of your project and the -d or --for-docker flag like ./bin/bootstrap.sh --name=my_awesome_project -d
    1. Run ./bin/bootstrap.sh --help for the full details.
  3. (Optional) If you want to deny access to the database from outside of the docker-compose network, remove the ports key in the docker-compose.yml from the db service.
  4. (Optional) Run the tests to make sure everything is working with: bin/rspec ..
  5. You can now try your REST services!

See Docker docs for more info

Dev scripts

This template provides a handful of scripts to make your dev experience better!

You don't have to use these but they are designed to run the same when running with Docker or not. To illustrate, bin/rails console will run the console in the docker container when running with docker and locally when not.

Gems

Optional configuration

API Docs

See API documentation docs for more info

Code quality

With bundle exec rails code:analysis you can run the code analysis tool, you can omit rules with:

Impersonation

The rails_api_base incorporates a user impersonation feature, allowing AdminUsers to assume the identity of other Users. This feature is disabled by default.

See Impersonation docs for more info

Monitoring

In order to use New Relic to monitor your application requests and metrics, you must setup NEW_RELIC_API_KEY and NEW_RELIC_APP_NAME environment variables. To obtain an API key you must create an account in the platform.

Configuring Code Climate

  1. After adding the project to CC, go to Repo Settings
  2. On the Test Coverage tab, copy the Test Reporter ID
  3. Set the current value of CC_TEST_REPORTER_ID in the GitHub secrets and variables

Code Owners

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.

Credits

Rails API Base is maintained by Rootstrap with the help of our contributors.

<img src="https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png" width="100"/>