Full Rails versus API-only Rails
Fast recall
Quick revision
Core answer
Whether the learner understands API-only mode as a different default stack rather than a different framework.
Claiming --api makes every action return JSON automatically or makes cookies impossible.
Compare controller base classes, middleware, generators, rendering responsibility, and incremental opt-in.
Interview-ready guide
Interview answer
A full Rails application is configured for server-rendered web pages. ApplicationController normally inherits from ActionController::Base, controllers can render Action View templates and layouts, and the default stack includes browser-oriented middleware and helpers for sessions, cookies, forgery protection, and other HTML workflows.
An API-only application is created with rails new service --api. Its controller base is ActionController::API, which includes a smaller set of controller modules, its middleware stack is reduced, and generators skip browser-facing files that a JSON service usually does not need.
For example, a mobile backend may accept JSON, load an Active Record model, and call render json: order, status: :ok. A full Rails storefront can use the same model and route concepts but render an ERB template inside a layout. The difference is the delivery stack, not whether Rails can use models or RESTful routes.
API mode does not magically serialize every return value or guarantee good API design. The action must still choose JSON, status, headers, errors, authentication, and versioning. Cookies, sessions, or other omitted features can be added, but doing so should be intentional because it changes middleware and browser-security responsibilities.
I choose API-only mode when Rails is primarily serving non-browser or separately rendered clients. I choose full Rails when the server owns HTML, forms, and navigation. Starting from the closest default keeps the application clear while Rails still permits a hybrid when requirements genuinely overlap.
Full Rails versus API-only Rails
Direct Answer
A full Rails application includes the controller, view, browser-session, asset, and middleware features needed to render HTML. An API-only application starts with ActionController::API, a smaller default middleware set, and generators aimed at JSON services, while still allowing omitted Rails features to be added deliberately.
Deep Dive & Architecture
The --api generator sets config.api_only = true. The generated ApplicationController inherits from ActionController::API, whose smaller module set focuses on request parameters, headers, rendering, redirects, status codes, and other API controller needs. Full applications inherit from ActionController::Base, which builds on the API controller foundation with browser-facing modules and Action View integration.
The middleware stack also starts smaller. Browser sessions and cookies are not assumed in the same way, and generators avoid views, helpers, and assets for ordinary resources. This reduces unused surface area, but it does not create a non-Rails microframework. The router still dispatches requests, Active Record still maps models when included, Active Job still runs work, and render json: still uses Rails rendering support.
Representation remains an action-level decision. Returning a Ruby object from a method does not by itself define an HTTP JSON response. The controller chooses a status, headers, and body, commonly with render json: or head. Validation errors need a stable error shape; created resources should use an appropriate success status and may include a Location header; a 204 response must not carry a body.
Features can be restored deliberately. A browser-based API using cookie authentication may add cookie and session middleware plus the relevant controller modules, then handle CSRF according to its credential model. An endpoint that also serves an HTML administration view may be better in a full app or separated behind a clear controller boundary. The important point is to understand every added feature's request and security behaviour.
The mode decision therefore follows clients and ownership. If Rails renders the document and handles form navigation, full mode offers coherent defaults. If independent clients own presentation and Rails supplies representations of resources, API-only mode avoids unused browser machinery. Teams should verify with bin/rails middleware, the controller ancestors, and generated files rather than relying on the label alone.
Choose the application mode from the delivered clients and operational needs, not from the word API in a project name. A service that renders no pages may still need cookies or browser protections, while a full-stack application can expose a small, well-designed JSON namespace.
Code Example
class ApplicationController < ActionController::API
end
class Api::OrdersController < ApplicationController
def show
order = Order.find(params[:id])
render json: { id: order.id, state: order.state }, status: :ok
end
end
ActionController::API provides a focused controller stack, while the action still chooses JSON and its status explicitly.
Common Mistakes & Pitfalls
Claiming --api makes every action return JSON automatically or makes cookies impossible.
Check your understanding
Answer these without looking back at the article.
- Which middleware might an API-only app add for cookie sessions?
- Does API-only mode remove Active Record?
- When is a full Rails application simpler than a separate SPA and API?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.