Why Use Rails for JSON APIs?

From the Rails Guides:

The first question a lot of people have when thinking about building a JSON API using Rails is: “isn’t using Rails to spit out some JSON overkill? Shouldn’t I just use something like Sinatra?”. [Or Express.js?]

For very simple APIs, this may be true. However, even in very HTML-heavy applications, most of an application’s logic lives outside of the view layer.

The reason most people use Rails is that it provides a set of defaults that allows developers to get up and running quickly, without having to make a lot of trivial decisions.

Tools

  • apiup - Rails project template to create an API pre-configured for JSON:API and OAuth 2 authentication

Sample APIs

  • How to JSON:API Sandbox—a JSON:API compliant web service with OAuth2 authentication. Try the app hosted or download it locally.

Resources

Rails Guides

The following pages in the Guides are relevant to API development:

Gems

  • rspec-rails—a popular Rails testing library. For APIs, especially check out request specs
  • Active Model Serializers—centralizes your logic to serialize models to JSON
  • Doorkeeper—authenticate users with the OAuth2 standard
  • Pundit—authorize users’ access to read and write records
  • JSONAPI::Resources—helps creating an API following the JSON:API spec. Maintained by the creators of JSON:API.
  • jsonapi-rails—alternate JSON:API gem
  • GraphQL—gem for creating GraphQL APIs

Deployment

API Documentation