Performance: API-only application setup
This setup affects initial page load speed and server response time by minimizing unnecessary frontend assets and middleware.
rails new myapp --api
# API-only mode disables views, asset pipeline, and reduces middlewarerails new myapp # default full-stack setup with views, assets, and middleware # serves HTML views and includes asset pipeline
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full-stack Rails app serving HTML views | Many DOM nodes generated by views | Multiple reflows due to large DOM | High paint cost from complex UI | [X] Bad |
| Rails API-only app serving JSON | No DOM generated by server | No reflows triggered by server | No paint cost from server response | [OK] Good |
--api flag?--api flag purpose--api flag creates a Rails app optimized for API use, focusing on JSON responses without HTML views.my_api?rails new app_name --api.rails new my_api --api matches the requirement exactly./api/greetings?
class Api::GreetingsController < ApplicationController
def index
render json: { message: 'Hello, API!' }
end
endindex action uses render json: to send a JSON response with a message.ActionController::UnknownFormat when requesting JSON. What is the likely cause?ActionController::UnknownFormat means the controller does not know how to respond to the requested format.render json:, Rails can't respond with JSON, causing this error.Pass the test and this pattern moves unknown