Some may feel that using Ruby on Rails as an API is a bit of an overkill. If you are working on a super simple API that may be true but who doesn’t want to take advantage of how easy it is to get up and running with rails. There are many great articles out there on this same subject but I wanted to go a bit further than just creating it and connecting a database.

We will go through the steps to create our API with the database and create some methods to handle some JSON data. For this example, we will call our API ‘my-dope-api’. For this example, I am storing my code on GitHub, and I’ll be using PostgreSQL for the database. Let’s get to it!

1 - Create The Directory For The Application

Decide where you want your application files to live then create the directory for it. I will name my directory apiDemo.

mkdir apiDemo

2 - Navigate Into That Directory

cd apiDemo

3 - Check Rails Version

Make sure you are using the latest version by running:

// Check rails version
rails -v

// If you do not have it 
gem install rails
// If it is outdateda
gem update rails

If you have it installed you should see something like this.

Image for post

#ruby-on-rails #ruby #api

How to Build an API with Ruby on Rails
4.75 GEEK