← Back to list

⚑ Supercharge Your Rails APIs with Fast JSON API πŸš€

Build Blazing Fast APIs in Ruby on Rails Like a Pro πŸ”₯

Ravi Prakash Β· 2026-05-12 15:19 Β· 0 claps Β· 3.8 min read paywalled
#ruby #ruby-on-rails #ruby-on-rails-development #rails #json
Open on Medium β†—
Wiki topics: 🌐 · Web Development

⚑ Supercharge Your Rails APIs with Fast JSON API πŸš€

Build Blazing Fast APIs in Ruby on Rails Like a Pro πŸ”₯

β€œYour API is only as good as its response speed.” ⚑

Modern frontend applications:

  • βš›οΈ React
  • β–² Next.js
  • πŸ“± Flutter
  • πŸ“² React Native
  • πŸ–₯️ Vue

all depend heavily on APIs.

And if your Rails API becomes slow… 😭

Your entire application feels slow.

That’s where Fast JSON API comes in πŸ’₯

🌟 What You’ll Learn

By the end of this guide, you’ll know how to:

βœ… Build super-fast JSON APIs βœ… Serialize Rails models cleanly βœ… Include relationships βœ… Customize responses βœ… Improve API performance βœ… Follow JSON:API standards βœ… Build production-ready APIs

And trust me…

Your API responses will become ✨ BEAUTIFUL ✨

πŸ€” What is Fast JSON API?

Fast JSON API is a blazing-fast serializer library originally built by:

Netflix πŸ”₯

It helps Rails applications:

βœ… Convert models into JSON βœ… Improve API performance βœ… Structure responses cleanly βœ… Reduce serialization time dramatically

😭 The Problem with Default Rails JSON

Most beginners do this:

render json: @users

And Rails returns EVERYTHING 😡

Example:

{
  "id": 1,
  "name": "Ravi",
  "created_at": "...",
  "updated_at": "...",
  "password_digest": "..."
}

Problems:

❌ Exposes unnecessary data ❌ Slow for large responses ❌ Hard to customize ❌ Poor API structure

πŸš€ Why Fast JSON API is Amazing

With Fast JSON API:

βœ… Faster serialization βœ… Cleaner responses βœ… Better frontend integration βœ… Relationship support βœ… Smaller payloads βœ… Standardized APIs

πŸ—οΈ Final Architecture

Rails Model
     ↓
Serializer
     ↓
Fast JSON API
     ↓
Beautiful JSON Response πŸš€

βš™οΈ Step 1 β€” Create Rails API App

You can use existing Rails app OR create API-only app.

rails new blog_api --api

Move into project:

cd blog_api

πŸ“¦ Step 2 β€” Add Fast JSON API Gem

Open Gemfile

gem 'jsonapi-serializer'

Install gems:

bundle install

πŸ€” Wait… Why jsonapi-serializer?

The original fast_jsonapi gem became inactive.

Now the maintained version is:

jsonapi-serializer

And it’s AWESOME πŸ”₯

🧱 Step 3 β€” Generate Sample Model

Let’s create a blog system.

rails generate model Post title:string content:text author:string
rails db:migrate

🧠 Step 4 β€” Create Some Data

Open Rails console:

rails console

Create sample records:

Post.create!(
  title: "Fast JSON API Guide",
  content: "Build blazing fast APIs",
  author: "Ravi"
)

πŸ”₯ Step 5 β€” Generate Serializer

Create:

app/serializers/post_serializer.rb

Add:

class PostSerializer
  include JSONAPI::Serializer
  attributes :title, :content, :author
end

πŸŽ‰ Congratulations

You just created your first serializer πŸš€

⚑ Step 6 β€” Use Serializer in Controller

Generate controller:

rails generate controller api/posts

🧠 Controller Code

class Api::PostsController < ApplicationController
  def index
    posts = Post.all
    render json: PostSerializer.new(posts).serializable_hash
  end
end

πŸ›£οΈ Step 7 β€” Add Routes

namespace :api do
  resources :posts, only: [:index]
end

πŸš€ API Response

Visit:

GET /api/posts

Response:

{
  "data": [
    {
      "id": "1",
      "type": "post",
      "attributes": {
        "title": "Fast JSON API Guide",
        "content": "Build blazing fast APIs",
        "author": "Ravi"
      }
    }
  ]
}

πŸ”₯ CLEAN πŸ”₯ STRUCTURED πŸ”₯ PROFESSIONAL

✨ Step 8 β€” Add Custom Attributes

Want computed fields? 😎

class PostSerializer
  include JSONAPI::Serializer
  attributes :title, :content
  attribute :short_content do |post|
    post.content.truncate(50)
  end
end

🎯 Result

{
  "short_content": "Build blazing fast APIs..."
}

Magic ✨

πŸ”— Step 9 β€” Add Relationships

Let’s add comments.

Generate Model

rails generate model Comment body:text post:references
rails db:migrate

🧱 Associations

Post Model

has_many :comments

Comment Model

belongs_to :post

✨ Create Comment Serializer

class CommentSerializer
  include JSONAPI::Serializer
  attributes :body
end

πŸ”₯ Update Post Serializer

class PostSerializer
  include JSONAPI::Serializer
  attributes :title, :content
  has_many :comments
end

πŸš€ Include Relationships

render json: PostSerializer.new(
  posts,
  include: [:comments]
).serializable_hash

πŸŽ‰ Result

Now API includes:

βœ… Posts βœ… Associated comments

in ONE response πŸ”₯

⚑ Step 10 β€” Improve Performance

Fast JSON API is FAST…

but you still need to avoid N+1 queries 😭

❌ Bad

posts = Post.all

βœ… Good

posts = Post.includes(:comments)

Massive performance improvement πŸš€

🧠 Step 11 β€” Conditional Attributes

Show fields only for admins.

attribute :internal_notes,
  if: Proc.new { |record, params|
    params[:admin] == true
  }

Usage

PostSerializer.new(
  posts,
  params: { admin: true }
)

🎯 Step 12 β€” Meta Information

Add pagination info.

render json: PostSerializer.new(
  posts,
  meta: {
    total: posts.count
  }
).serializable_hash

✨ Response

{
  "meta": {
    "total": 25
  }
}

πŸ”₯ Step 13 β€” Serializer Features You’ll Love

⚑ Lightning Fast

Much faster than:

  • ActiveModelSerializers
  • JBuilder

🎯 JSON:API Standard

Frontend developers LOVE standardized APIs 😍

🧼 Clean Code

Instead of messy controllers:

render json: ...

you move formatting into serializers.

Beautiful architecture ✨

πŸ”— Relationship Support

Easily serialize:

βœ… has_many βœ… belongs_to βœ… nested relationships

πŸ“‰ Smaller Payloads

Send ONLY required data.

This improves:

βœ… Performance βœ… Mobile experience βœ… Frontend speed

πŸ›‘οΈ Step 14 β€” Production Best Practices

βœ… Cache Serialized Responses

cache_options store: Rails.cache,
              namespace: 'jsonapi',
              expires_in: 1.hour

Huge speed boost ⚑

βœ… Use Pagination

Never return 10,000 records 😭

Use:

βœ… Version Your APIs

Good practice:

/api/v1/posts

πŸš€ Step 15 β€” Real-World API Structure

app/
 β”œβ”€β”€ controllers/
 β”‚    └── api/
 β”‚         └── v1/
 β”‚
 β”œβ”€β”€ serializers/
 β”‚    β”œβ”€β”€ post_serializer.rb
 β”‚    └── comment_serializer.rb
 β”‚
 └── models/

Professional Rails architecture πŸ”₯

πŸŽ‰ Final Result

You now have:

βœ… Fast Rails APIs βœ… Structured JSON responses βœ… Relationship serialization βœ… Better frontend integration βœ… Production-ready serializers βœ… High-performance API architecture

🌟 Bonus Ideas

Take it NEXT LEVEL 😎

Add:

  • API authentication πŸ”
  • JWT tokens
  • API rate limiting 🚦
  • GraphQL
  • API documentation πŸ“š
  • Swagger/OpenAPI
  • JSON caching
  • Background jobs

πŸ’¬ Final Thoughts

Fast JSON API makes Rails APIs:

⚑ Faster 🧼 Cleaner πŸš€ Scalable 🎯 Professional

Instead of dumping raw database data…

you start building APIs frontend developers LOVE ❀️

And honestly?

Once you use serializers properly…

there’s no going back 😎


메타데이터
post_id
b004e1cf0d8a
slug
supercharge-your-rails-apis-with-fast-json-api-b004e1cf0d8a
url
https://medium.com/@raviskit2012/supercharge-your-rails-apis-with-fast-json-api-b004e1cf0d8a
canonical_url
https://medium.com/@raviskit2012/supercharge-your-rails-apis-with-fast-json-api-b004e1cf0d8a
author_url
https://medium.com/@raviskit2012
status
ok
fetched_at
2026-06-09 15:37:30