β‘ Supercharge Your Rails APIs with Fast JSON API π
Build Blazing Fast APIs in Ruby on Rails Like a Pro π₯
β‘ 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