Build rest api

From FerroxLabs/murage · View interactive version

Build rest api is an AI agent skill from the GitHub repository FerroxLabs/murage. Orchestrates the process of designing, building, testing, and documenting a REST API from specification through production-ready documentation, chaining five software-development skills into a structured backend workflow. Use when the user needs to build a REST API from scratch with design-first met

How to use this skill

Skill file

Build a REST API

Estimated time: 3-10 days (depending on endpoint count, database complexity, and test coverage depth)

This workflow chains five atomic skills into the complete process of building a production-quality REST API. Each step produces artifacts that feed directly into the next, creating a traceable path from API specification to versioned, documented, and tested endpoints. The workflow assumes you are building a custom backend service that exposes HTTP endpoints for consumption by frontends, mobile apps, or third-party integrators.

When to Use

Prerequisites

Before starting this workflow, ensure:

  1. Business requirements are defined: You know what resources the API exposes, who the consumers are (web frontend, mobile app, third-party), and the core operations each consumer needs
  2. Technology stack is selected: You have chosen a backend language and framework (Node.js with Express, Python with FastAPI, Go with Gin, Ruby on Rails, Java with Spring, etc.)
  3. Database is chosen: You know which database engine you will use (PostgreSQL, MySQL, MongoDB, etc.) and have access to a development instance
  4. Development environment is ready: Local development setup is complete with the chosen language, framework, and database running locally or in containers

Steps

Step 1: Design the API Specification (uses: rest-api-design)

Define the complete API contract before writing any implementation code. This design-first approach prevents the common failure mode of building endpoints ad-hoc and discovering inconsistencies during integration. The specification becomes the single source of truth for every subsequent step.

Step 2: Implement the API Endpoints (uses: rest-api-implementation)

Translate the API specification from Step 1 into working code. Each endpoint is implemented to match the specification exactly -- same paths, same request validation, same response shapes, same status codes. Deviations from the specification are bugs, not features.

Step 3: Design and Apply Database Migrations (uses: database-migration-patterns)

Create the database schema that supports the API resources defined in Step 1 and implemented in Step 2. Migrations are versioned, reversible scripts that evolve the database schema alongside the application code. This step ensures the database structure matches the API contract.

Step 4: Write Integration Tests (uses: integration-testing-patterns)

Test the API endpoints against a real (or realistic) database to verify that the implementation matches the specification. Integration tests exercise the full request-response cycle: HTTP request goes in, database is queried or modified, HTTP response comes out. These tests catch the bugs that unit tests miss -- serialization errors, database constraint violations, middleware ordering issues.

Step 5: Version and Document the API (uses: api-versioning)

Create documentation that enables consumers to integrate with the API without reading the source code, and establish a versioning strategy that allows the API to evolve without breaking existing consumers. This step synthesizes all prior outputs into the consumer-facing deliverable.

Decision Points

Failure Handling

Edge Cases

Expected Outcome

When this workflow is complete, the user will have:

  1. A complete API specification that serves as the single source of truth for all endpoints, request/response formats, and error handling
  2. A working API server with all endpoints implemented, validated against the specification, with consistent error handling and correct HTTP status codes
  3. A versioned database schema with reversible migrations, proper indexes, and constraints that enforce data integrity below the application layer
  4. An integration test suite that exercises every endpoint through the full HTTP request-response cycle, catching serialization, validation, and authorization bugs
  5. Consumer-facing API documentation with endpoint reference, authentication guide, pagination guide, versioning policy, and verified request/response examples taken directly from passing tests
  6. A versioning strategy and deprecation policy that allows the API to evolve without breaking existing consumers
  7. Confidence that any developer can integrate with the API using only the documentation, without needing to read the source code or ask the backend team questions

Output Format

The workflow produces these artifacts at each step, with later steps referencing earlier outputs:

project-root/
  docs/
    api-specification.md     # Step 1: Complete API contract
    migration-strategy.md    # Step 3: Database migration approach
    api-reference/           # Step 5: Consumer-facing documentation
      endpoints.md           # Endpoint reference with examples
      authentication.md      # Auth guide
      versioning.md          # Versioning policy and changelog
  src/
    routes/                  # Step 2: Route handlers per resource
    middleware/               # Step 2: Validation, auth, error handling
    models/                  # Step 2: Database models
    migrations/              # Step 3: Versioned migration files
  tests/
    integration/             # Step 4: Integration test suites per resource
    fixtures/                # Step 4: Test data factories
  package.json / pyproject.toml / go.mod  # Dependencies

Example

Scenario: "Build a REST API for a task management application with users, projects, and tasks."

Input: Requirements: user registration and authentication, project CRUD scoped to authenticated users, task CRUD within projects with status tracking (todo, in-progress, done), task assignment to team members. Technology: Python with FastAPI, PostgreSQL database. Consumers: React web frontend and future React Native mobile app.

Output: Production-ready REST API with 12 endpoints, integration test suite, versioned database schema, and consumer-facing documentation.

Step 1 (rest-api-design):

Design the API specification. Resources: users (registration + login), projects (CRUD scoped to authenticated user), tasks (CRUD within project, with status transitions: todo, in-progress, done, assignee field). Endpoints: POST /v1/users (register), POST /v1/sessions (login), GET/POST /v1/projects, GET/PATCH/DELETE /v1/projects/:id, GET/POST /v1/projects/:id/tasks, GET/PATCH/DELETE /v1/tasks/:id. Pagination: cursor-based with 20 items per page default, max 100. Error format: JSON with error_code (string), message (human-readable), details (array of field-level errors). Authentication: Bearer token in Authorization header, 401 for missing or expired token.

Step 2 (rest-api-implementation):

Implement all endpoints with Pydantic request validation. POST /v1/projects validates: name (required, 1-100 characters), description (optional, max 500 characters). GET /v1/projects/:id/tasks supports query parameters: status (enum filter), assignee_id (UUID filter), sort (created_at or due_date), order (asc or desc). All database queries use parameterized statements via SQLAlchemy. Error handling middleware catches ValidationError (400), AuthenticationError (401), NotFoundError (404), and DatabaseError (503) with consistent JSON responses.

Step 3 (database-migration-patterns):

Create migrations: users table (id UUID, email unique, password_hash, name, created_at, updated_at), projects table (id UUID, name, description, owner_id FK users, created_at, updated_at), tasks table (id UUID, title, description, status enum, project_id FK projects, assignee_id FK users nullable, due_date nullable, created_at, updated_at). Indexes: tasks by project_id, tasks by assignee_id, tasks by (project_id, status), users by email. Seed script creates a test user and sample project for development environments.

Step 4 (integration-testing-patterns):

Write tests using httpx test client against a test database: create user and verify 201 response with user object (no password_hash in response). Create project, then GET /v1/projects and verify the project appears in the list. Create task within project, PATCH task status from todo to in-progress, verify status change persists on subsequent GET. Attempt to GET another user's project and verify 404 (not 403, to avoid leaking resource existence). POST task with invalid status value "cancelled" and verify 400 with field-level error detail pointing to the status field. Total: 35 integration tests covering all 12 endpoints.

Step 5 (api-versioning):

Generate API documentation from the specification with verified test examples as request/response samples. URL-based versioning at /v1/ prefix. Deprecation policy: 6-month notice with Sunset header on deprecated endpoints. Documentation includes: quick start guide (register, log in, create a project, create a task in 4 API calls), authentication section with token refresh flow, pagination section with cursor examples, and endpoint reference with request/response examples copied directly from passing integration tests.

Result: A production-ready task management API with 12 endpoints, 35 integration tests, versioned database schema with 3 migration files, and consumer documentation that a frontend developer can follow to integrate without backend team support.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.