rails-apilisted
Install: claude install-skill mickzijdel/rails-toolkit
# Rails API
Apply when: building a JSON API with Rails, adding an API namespace to an existing Rails app, or evaluating API design choices.
---
## 1. API-only mode
For standalone APIs, generate with `--api` to strip unnecessary middleware (views, assets, sessions, cookies):
```bash
rails new my_api --api
```
`ApplicationController` inherits from `ActionController::API` instead of `ActionController::Base`. Renders nothing for unknown formats (no HTML fallback).
For an API namespace added to an existing full-stack app, keep `ApplicationController < ActionController::Base` and use a dedicated base for API controllers:
```ruby
# app/controllers/api/base_controller.rb
module Api
class BaseController < ActionController::API
include ActionController::MimeResponds
before_action :require_api_authentication
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from ActionController::ParameterMissing, with: :unprocessable_entity
end
end
```
## 2. Versioning
Namespace by version so you can introduce `v2` without breaking `v1` clients:
```ruby
# config/routes.rb
namespace :api do
namespace :v1 do
resources :articles, only: [:index, :show, :create, :update, :destroy]
resources :users, only: [:show, :create]
end
end
```
Controllers live at `app/controllers/api/v1/` and inherit from `Api::BaseController`. URL versioning (the above) is simpler and visible in logs; use `Accept` header versioning only if you have a specific reason.
## 3