home / skills / shipshitdev / library / api-design-expert

api-design-expert skill

/bundles/backend/skills/api-design-expert

This skill guides RESTful API design and OpenAPI documentation for NestJS apps, improving versioning, error handling, and DTO validation.

npx playbooks add skill shipshitdev/library --skill api-design-expert

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
2.0 KB
---
name: api-design-expert
description: Expert in RESTful API design, OpenAPI/Swagger documentation, versioning, error handling, and API best practices for NestJS applications
---

# API Design Expert Skill

Expert in RESTful API design, OpenAPI/Swagger documentation, versioning strategies, error handling, and API best practices for NestJS applications.

## When to Use

- Designing new API endpoints
- Creating RESTful APIs
- Writing OpenAPI/Swagger documentation
- Implementing API versioning
- Designing error responses
- Creating DTOs and validation
- Implementing pagination, filtering, sorting

## Project Context Discovery

Before providing guidance:

1. Check `.agents/SYSTEM/ARCHITECTURE.md` for API patterns
2. Review existing controllers and DTOs
3. Check for OpenAPI/Swagger setup
4. Review versioning strategy

## Core Principles

### RESTful Design

```typescript
// Use nouns, plural, hierarchical
GET    /api/users
GET    /api/users/:id
POST   /api/users
PUT    /api/users/:id
DELETE /api/users/:id
GET    /api/users/:id/posts
```

### HTTP Status Codes

- `200 OK` / `201 Created` / `204 No Content`
- `400 Bad Request` / `401 Unauthorized` / `403 Forbidden`
- `404 Not Found` / `409 Conflict` / `500 Internal Server Error`

### Response Format

```typescript
// Single resource
{ "data": {...}, "meta": {...} }

// List with pagination
{ "data": [...], "pagination": { "page", "limit", "total" } }
```

### Error Format

```typescript
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [...],
    "timestamp": "...",
    "path": "/api/users"
  }
}
```

## Best Practices

- Consistent naming conventions
- Validate all inputs with DTOs
- OpenAPI/Swagger documentation
- Authentication on all endpoints
- Pagination for lists
- Version APIs from the start

---

**For complete DTO examples, pagination/filtering/sorting patterns, versioning strategies, OpenAPI setup, CRUD controller patterns, nested resources, bulk operations, and anti-patterns, see:** `references/full-guide.md`

Overview

This skill is an API design expert focused on RESTful APIs, OpenAPI/Swagger documentation, versioning, error handling, and API best practices for NestJS applications. It provides concrete guidance for endpoint design, DTOs and validation, response shapes, and operational patterns like pagination and filtering. The aim is to produce consistent, maintainable APIs that integrate well with NestJS tooling and OpenAPI generation.

How this skill works

I inspect project controllers, DTOs, and existing OpenAPI setup to determine current patterns and gaps. I recommend concrete changes: route naming, status codes, response and error formats, DTO validation rules, and a versioning strategy. I also provide sample controller/DTO snippets, pagination/filtering patterns, and guidance for documenting endpoints in Swagger.

When to use it

  • Designing new RESTful endpoints or microservice APIs with NestJS
  • Creating or improving OpenAPI/Swagger documentation for discoverability
  • Defining DTOs, input validation, and error response contracts
  • Implementing API versioning and backward-compatibility strategies
  • Adding pagination, filtering, sorting, or nested resource patterns

Best practices

  • Use plural, noun-based routes and hierarchical nesting for resources
  • Return consistent envelope shapes: { data, meta } for single and paginated responses
  • Validate all inputs with DTOs and class-validator before business logic
  • Use standard HTTP status codes and map errors to structured error objects
  • Start versioning early (URI or header) and document breaking changes in OpenAPI
  • Protect endpoints with authentication and document scopes in Swagger

Example use cases

  • Refactor an existing controller to follow RESTful naming and update DTO validation
  • Add paginated list endpoints with consistent pagination metadata and links
  • Create OpenAPI tags, request/response schemas, and example payloads for Swagger UI
  • Define a versioning strategy (v1/v2) and migration plan for breaking changes
  • Standardize error responses with codes, details, timestamps, and request paths

FAQ

Which versioning approach should I pick?

Choose URI versioning for public APIs for clarity (e.g., /v1/...), or header versioning for internal APIs when you want cleaner paths; document any choice in OpenAPI and support redirected deprecation.

How should I format errors?

Return a structured error object with a code, human message, optional details array, timestamp, and request path so clients can programmatically react and surface helpful messages.