All skills
asyrafhussin avatar

/api-design-patterns

@1de3a7a

RESTful API design, error handling, versioning, and best practices. Use when designing APIs, reviewing endpoints, implementing error responses, or setting up API structure. Triggers on "design API", "review API", "REST best practices", or "API patterns".

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/api-design-patterns

This session only. Nothing lands on disk.

rulesdoc-openapi.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

OpenAPI/Swagger Specification

Impact: MEDIUM (Cuts API integration time by 50% with machine-readable docs)

An OpenAPI specification serves as both documentation and a contract. It enables auto-generated client SDKs, interactive docs, and automated testing. Without it, developers rely on outdated wikis or reverse-engineering API behavior from code.

Incorrect

// ❌ No formal API documentation

// Option A: Nothing at all — developers read source code
// Option B: Outdated wiki page last edited 18 months ago
// Option C: Slack messages like "hey how does the /users endpoint work?"
// Option D: README with a few curl examples that no longer match the API

Problems:

  • Developers spend hours discovering endpoints and request formats by trial and error
  • No single source of truth — information scattered across wikis, Slack, and code comments
  • Documentation drifts out of sync with the actual API
  • Cannot auto-generate client SDKs, mock servers, or test suites

Correct

Minimal OpenAPI 3.1 Specification

# ✅ openapi.yaml — machine-readable, always up to date
openapi: "3.1.0"
info:
  title: User Management API
  version: "1.2.0"
  description: API for managing user accounts
  contact:
    name: API Support
    email: api-support@example.com

servers:
  - url: https://api.example.com/v1
    description: Production
  - url: https://staging-api.example.com/v1
    description: Staging

security:
  - bearerAuth: []

paths:
  /users:
    get:
      summary: List users
      operationId: listUsers
      tags:
        - Users
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            default: 1
        - name: per_page
          in: query
          schema:
            type: integer
            default: 20
            maximum: 100
        - name: status
          in: query
          schema:
            type: string
            enum: [active, inactive, suspended]
      responses:
        "200":
          description: A paginated list of users
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/User"
                  meta:
                    $ref: "#/components/schemas/PaginationMeta"
              example:
                data:
                  - id: 123
                    first_name: Jane
                    last_name: Doe
                    email: jane@example.com
                    status: active
                    created_at: "2024-01-15T10:30:00Z"
                meta:
                  page: 1
                  per_page: 20
                  total: 142
                  total_pages: 8
        "401":
          $ref: "#/components/responses/Unauthorized"

    post:
      summary: Create a user
      operationId: createUser
      tags:
        - Users
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateUserRequest"
            example:
              first_name: Jane
              last_name: Doe
              email: jane@example.com
              password: secureP@ssw0rd
      responses:
        "201":
          description: User created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: "#/components/schemas/User"
        "422":
          $ref: "#/components/responses/ValidationError"

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
        first_name:
          type: string
        last_name:
          type: string
        email:
          type: string
          format: email
        status:
          type: string
          enum: [active, inactive, suspended]
        created_at:
          type: string
          format: date-time
      required:
        - id
        - first_name
        - last_name
        - email
        - status

    CreateUserRequest:
      type: object
      properties:
        first_name:
          type: string
          minLength: 1
          maxLength: 100
        last_name:
          type: string
          minLength: 1
          maxLength: 100
        email:
          type: string
          format: email
        password:
          type: string
          minLength: 8
      required:
        - first_name
        - last_name
        - email
        - password

    PaginationMeta:
      type: object
      properties:
        page:
          type: integer
        per_page:
          type: integer
        total:
          type: integer
        total_pages:
          type: integer

  responses:
    Unauthorized:
      description: Authentication required
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  code:
                    type: string
                    example: UNAUTHORIZED
                  message:
                    type: string
                    example: Authentication required

    ValidationError:
      description: Request validation failed
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  code:
                    type: string
                    example: VALIDATION_ERROR
                  message:
                    type: string
                  details:
                    type: array
                    items:
                      type: object
                      properties:
                        field:
                          type: string
                        code:
                          type: string
                        message:
                          type: string

Recommended Tools

Swagger UI      — Interactive docs with "Try it out" button
Redoc           — Clean, responsive three-panel documentation
Stoplight       — Visual OpenAPI editor with linting
Spectral        — OpenAPI linting and validation CLI
openapi-generator — Auto-generate client SDKs in 40+ languages

Benefits:

  • Single source of truth that stays in sync with the codebase
  • Auto-generate client SDKs, mock servers, and test stubs
  • Interactive documentation lets developers test endpoints in the browser
  • CI/CD can validate the spec to catch breaking changes before deploy

Reference: OpenAPI Specification 3.1

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill is a comprehensive documentation library for RESTful API design patterns. It provides best practices for resource design, error handling, security, and documentation. The skill contains no executable code, malicious instructions, or hidden functionality, and its references are restricted to well-known technical documentation sources.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    4/28 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 1de3a7a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
metadata
{
  "author": "agent-skills",
  "version": "2.0.0"
}

README badge

README badge for asyrafhussin/agent-skills/api-design-patterns