Rails 5: API-only Application – Quick Start

Brief description how to create API-only Rails 5 Application.


1. Create Project

If you want create project for specific database:

If you want create project without database (without Active Record):

2.  Setup access to Database

In this step is presented how to setup the access to MySQL database. If you created a project without Active Record, you can skip this step.

Add database user and password to config/secrets.yml:

Add DB_USER and DB_PASS as host’s environment variables. On Ubuntu, you can add following at the end of ~/.bashrc:

Replace root and my_password with your settings. After that, open new session in your terminal or run:


Set database’s user and password in config/database.yml:


Create database:


3. Enable CORS

Add to Gemfile (or uncomment):


Add to config/initializers/cors.rb:

Be sure that you have setup right origins above:


4. Test

Run server to verify if does it work:


Tomasz Antas

Ruby on Rails developer and Web designer.
The area of his interest includes Popular Science, Internet of Things, Wearables, AI and Virtual/Augmented Reality.

Latest posts by Tomasz Antas (see all)

Thanks for reading!