Building a data API with Ruby on Rails 5: Part 1 — Setup and Routing. Corey Schaf Follow Oct 4, 2018 · Unlisted

This is the second part of my ruby on rails series. Part one can be found here: Ruby and RVM. The source code is available on Github. I can also be found on twitter @corey_s_, and on twitch at twitch.tv/jastora.

In this tutorial we will be starting to lay the foundation for our rails 5 API. We wont be building a traditional demo API, but something a little more useful. The idea behind this is to build an API that will allow us to log data from various applications that have access to our endpoint. This is useful if we want to see real time results from our logging in a mobile app, a game demo or even a web app. As we progress through the tutorials we will be adding various features such as authentication, JWT support, spec testing, some database tweaking and devops/CI/deployment to a cloud provider such as Heroku.

High level of our API’s purpose.

We can aggregate data from anything with an HTTP interface. We could aggregate crashes in a mobile app or even aggregate player data from a game we built so we could determine where players die a lot, where they give up, average level time, etc. The possibilities are endless.

Generating our code

First we will be setting up a new Ruby on Rails project, stripped down to the bare essentials needed for a JSON API. Since we are just using this strictly as an API, we will pass in the --api to the command line as follows:

> rails new data_analytics --api

This will bootstrap our base project configured for our API needs. It does a few things behind the scenes.

Configures our app by limiting the amount of needed middleware. Our main ApplicationController will now inherit from ::API Adjusts the generators to skip generating views, helpers and assets.

Official notes can be found here: Link