Step-By-Step Guide to Using Javascript Front-End with a Rails App Backend to Make Your Own API

I was thrown into the fire yesterday. Here’s a checklist so you can cry tears of joy instead of suffering.

go from this

Image for post

to this

Image for post

or even this

Image for post

without this

Image for post
  1. create and fill the db/migrate/ migrations rb files that inherit from ActiveRecord::Migration
  2. run rails db:migrate. You will see in the terminal if they were successfully created or if there was an (probably syntax in the create_migration file) error.
  3. confirm the db/schema.rb looks right
  4. create and fill the db/seeds.rb files
  5. run rails db:seed
  6. use rails c or rails console (or database browser software) to confirm the database has been seeded properly.
  7. add appropriate routes in config/routes.rb on the backend
  8. create the app/models model rb files that inherit from ApplicationRecord which inherits from ActiveRecord::Base and designate any relationships
  9. create the matching controllers inheriting from ApplicationController which inherits from ApplicationController:::Base
  10. create and fill app/services/ serializer.rb file for the model
  11. fill in matching controller actions in the corresponding controller.rb in app/controllers/ to pull data from the database and render json: with the data or with plain text string. no need for instance variables because we’re not passing the data to erb views.
  12. run rails s to start up server
  13. confirm at your local server address that the API is rendering data

Written by

Product manager | Leading with empathy.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store