Performance: Why Rails API mode exists
This affects the initial page load speed and server response time by reducing unnecessary HTML rendering and asset loading.
class UsersController < ActionController::API def index users = User.all render json: users end end
class UsersController < ApplicationController def index @users = User.all render :index # renders full HTML view with layout end end
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full Rails with HTML views | N/A (server-side) | N/A | Larger payload delays browser paint | [X] Bad |
| Rails API mode with JSON only | N/A (server-side) | N/A | Smaller payload enables faster paint | [OK] Good |
/api/users/1?
class Api::UsersController < ApplicationController
def show
user = User.find(params[:id])
render json: { id: user.id, name: user.name }
end
endActionController::UnknownFormat. What is the likely cause?Pass the test and this pattern moves unknown