Building Rails API’s With JSONAPI and JSONAPI-Resources

Sooner or later, every application needs an API. It will need to integrate with your microservices, peer client service, or your new front-end mobile and web apps. With JSONAPI, and JSONAPI-Resources, building your API platform is easy. You just add your own application magic. Along with one of these JSONAPI Client Libraries, your application can rule the world.

There is a lot of background that I won’t be covering. I’ll assume you are familiar with HTTP, REST, JSON, Rails Routing, and have some basic Rails experience. I’m writing the overview I wish I had when I started. Not all examples are complete or polished, but should be far enough along so you can “load” the problem into your head when starting work on your API.

Setup Rails 4.1, Spring, Rspec, and Guard

Rails 4.1 allows us to use Spring to run our rails and rake commands quickly by running your application in the background and avoiding the rails startup time penalty. It took me a little while to find this information, so here is my guide to setting this up.

I’m using the Rspec testing framework with the Guard event watcher as the test runner. Spring allows us to watch the test run almost immediately after hitting save of a file in the editor.

Git Is a Framework for Creating a Version Control System

TL;DR - Git is a low-level library. All development and deployment environments differ, so build your own development work flow system on top of git to build your best work flow environment.

The git version control system became hugely popular once it was introduced, and along with Github, achieved a dominant role in open source to enterprise development.

Git is powerful, even complicated, but also allows a novice to start with minimal training. The more I use git, the more I start finding odd corners that I need to head to google to find out more how to use it. There are some parts of it that are just darn incomprehensible unless you understand the internals, so it becomes hard to guess where to look to find your answers.

REST API’s Are Crud

REST promotes CRUD. CRUD is for databases, not applications.

Databases generally have four operations to a set of data: Create, Read, Update, and Delete; these four operations are known by the acronym CRUD. An SQL-based relational database (like PostgreSQL, MySQL, etc.) have 4 cooresponding statements:

  • Insert -> Create
  • Select -> Read
  • Update -> Update
  • Delete -> Delete

The CouchDB database and SOLR search engine operate natively over a REST interface. Your applications perform CRUD operations on these data stores by employing the above style of request.

Architectures based on REST, like Ruby on Rails, builds the application on table resources to perform CRUD operations. By doing this, we get a free API into the application callable from any platform capable of making HTTP/REST calls.