API Development Patterns
Comprehensive guide to building production-ready REST APIs in Rails with serialization, authentication, versioning, rate limiting, and testing. Trigger keywords: REST API, JSON, serialization, versioning, authentication, JWT, rate limiting, API controllers, request specs, API testing, endpoints, responses
npx skills add majiayu000/claude-skill-registry --skill api-development-patterns --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Describes patterns and best practices for building production-grade REST APIs in Rails 7.x/8.x, covering routing conventions, HTTP methods and status codes, serialization strategies, authentication (JWT and API keys), authorization, versioning, pagination, rate limiting, and standardized error handling.
How it works
- Establishes RESTful conventions: resource-oriented routes, nested resources with limits, and specific member/collection actions.
- Specifies standard HTTP actions and their success/error statuses, plus corresponding response bodies (e.g., 201 Created for create, 204 No Content for destroy).
- Provides concrete controller examples (index, show, create, update, destroy) and a before_action for authentication, with a rescue strategy for not found errors.
- Details multiple serialization options: Blueprinter (with views and associations), JSONAPI::Serializer, and Alba, including installation steps and usage.
- Outlines authentication approaches:
- JWT-based tokens with a JsonWebTokenService for encode/decode, a base API controller for authentication, and an authentication controller for login/logout.
- API Keys as an alternative with a model, migration, and a controller filter for key-based auth.
- Describes authorization using Pundit policies and how to apply authorize in controllers.
- Describes versioning strategies: URL versioning and header-based versioning, with code sketches for routes and a simple ApiVersion matcher.
- Details pagination options: Kaminari and Pagy with example controller code and metadata extraction.
- Explains rate limiting using Rack::Attack with multiple throttles (by IP, token, login attempts) and a custom throttled response.
- Provides standardized error handling in a base controller, with methods to render structured error responses for various exceptions, and examples of the error payload structure.
When to use it
- When implementing a Rails-based REST API and you want a comprehensive, production-ready blueprint covering routing, serialization, auth, versioning, rate limiting, and error handling.
- When you need concrete code samples for controllers, serializers, policies, and middleware configuration.
What it can touch
- Routes: Ruby code in config/routes.rb for API namespaces and versioning setups.
- Controllers: Api::V1::..., Api::BaseController, Api::AuthenticationController, PostController, etc.
- Serializers/Blueprints: Blueprinter, JSONAPI::Serializer, Alba usage files under app/blueprints or app/serializers.
- Authentication: app/services/json_web_token_service.rb, app/controllers/api/v1/authentication_controller.rb, app/controllers/api/base_controller.rb, and related modules.
- Authorization: app/policies/post_policy.rb and policy usage in controllers.
- Versioning: lib/api_version.rb and config/routes.rb patterns for v1/v2.
- Pagination: examples using Kaminari and Pagy in controllers.
- Rate limiting: config/initializers/rack_attack.rb and Gemfile entry for rack-attack.
- Error handling: app/controllers/api/base_controller.rb with render_error utilities.
Caveats
- Only factual patterns and code examples as stated; no speculative outcomes.
- Licensing is MIT for the skill; no implementation guarantees beyond described usage.
- Examples assume Rails 7.x/8.x and common gem ecosystems; exact compatibility should be verified in the target project.
# API Development Patterns Complete patterns and best practices for building production-grade REST APIs in Rails 7.x/8.x. ## RESTful API Conventions ### Resource-Oriented Design **Core Principles:** - Resources are nouns (not verbs): `/users`, `/posts`, not `/get_user` - Use HTTP methods for actions: GET (read), POST (create), PATCH/PUT (update), DELETE (destroy) - Nest resources for relationships, but limit nesting to 1-2 levels - Use plural resource names: `/users` not `/user` **Standard Resource Routes:** ```ruby # config/routes.rb Rails.application.routes.draw do namespace :api do namespace :v1 do resources :posts do resources :comments, only: [:index, :create] # Nested but limited member do post :publish post :archive end collection do get :trending end end # Flat route for comments by ID (better than deep nesting) resources :comments, only: [:show, :update, :destroy] end end end ``` ### HTTP Methods & Status Codes **Standard API Actions:** | Method | Action | Success Status | Body | |--------|--------|----------------|------| | GET | Index/List | 200 OK | Resource array + pagination | | GET | Show | 200 OK | Single resource | | POST | Create | 201 Created | Created resource |
- RESTful API Conventions
- Resource-Oriented Design
- HTTP Methods & Status Codes
- Serialization Patterns
- Blueprinter (Recommended)
- JSONAPI::Serializer (Alternative)
- Alba (Lightweight Alternative)
- Authentication
- JWT (JSON Web Tokens)
- API Keys (Alternative)
- Authorization
- Pundit for APIs
- Versioning Strategies
- URL Versioning (Recommended)
rake rswag:specs:swaggerize
What does the API Development Patterns skill do?
Comprehensive guide to building production-ready REST APIs in Rails with serialization, authentication, versioning, rate limiting, and testing. Trigger keywords: REST API, JSON, serialization, versioning, authentication, JWT, rate limiting, API controllers, request specs, API testing, endpoints, responses
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-development-patterns --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
