

Creating a new Rails app is super easy by itself. And, creating a Rails app set up as an API is not much different.
Because we are planning on deploying our app to Heroku we need to set it up with PostgreSQL as the database.
The default database in Rails is SQLite, but it is not supported by Heroku
Letโs start!
Run the following line in your terminal to update Rails
gem update rails
and then this line to get the current version of Rails
rails -v
rails new <<APP_NAME>> --api --database=postgresql
Replace theยย with the actual name of your app<<APP_NAME>>
Keep track of the development of your API by storing your code on GitHub.
Check thisย linkย to see how to add an existing project to a Github repository.
Follow thisย linkย to the Heroku Sign up page.
Next, we will need to install the Heroku CLI to be able to deploy our little project.
Check thisย linkย to see how to install the Heroku CLI.
Once installed the
heroku
command is available from your terminal.Run the following command in your terminal and enter your Heroku credentials when prompted
heroku login
Press Enter at the prompt to upload your existingย sshย key or create a new one, used for pushing code later on
Run the following command in your terminal to create a new app on Heroku
heroku create
After that, we are all set up to deploy our app to Heroku!
We are finally here!
Run the following commands in your terminal to deploy your app to Heroku
git add .
git commit -m "Deploy my super awesome Rails API"
git push heroku master
Side note โ if you are working on a different branch from theย master branch. You can run the following command to deploy your code
For example, if you are working on theย
feature-branch
git push heroku feature-branch:master
Thatโs it, our Rails API is now live!
Itโs an API-only application, itโs using PostgreSQL as the database and itโs deployed to Heroku.
Congratulate yourself. And then, get back to work, you have only begun.
Thanks for reading. And hopefully, this article helps you out.
Create your free account to unlock your custom reading experience.