API Contract
Overview
API Contract guides the creation of api-contract.md files that serve as the shared interface between backend and frontend agents during sprint execution. The contract defines request/response schemas, endpoint routes, TypeScript interfaces, and error formats so that implementation agents build to an agreed specification without direct coordination.
Prerequisites
- Sprint directory initialized at
.claude/sprint/[N]/
specs.md with defined feature scope and endpoint requirements
- Familiarity with RESTful API conventions (HTTP methods, status codes, JSON schemas)
- TypeScript knowledge for interface definitions (recommended)
Instructions
- Create
api-contract.md in the sprint directory (.claude/sprint/[N]/api-contract.md). Define each endpoint using the standard format: HTTP method, route path, description, request body, response body with status code, and error codes. See ${CLAUDE_SKILL_DIR}/references/writing-endpoints.md for the full template.
- Define TypeScript interfaces for all request and response types. Use explicit types instead of
any, mark optional fields with ?, and use string | null for nullable values. Reference ${CLAUDE_SKILL_DIR}/references/typescript-interfaces.md for canonical type patterns.
- For list endpoints, include pagination parameters and the
PaginatedResponse<T> wrapper. Standardize on page, limit, sort, and order query parameters as documented in ${CLAUDE_SKILL_DIR}/references/pagination.md.
- Document all response states: success (200, 201, 204), client errors (400, 401, 403, 404, 422), and empty states. Use a consistent error response format with
code, message, and optional details fields.
- Follow best practices from
${CLAUDE_SKILL_DIR}/references/best-practices.md: be specific about field constraints (e.g., "string, required, valid email format"), include request/response examples, reference shared types instead of duplicating, and omit implementation details (no database columns, framework names, or file paths).
- Share the contract file path in SPAWN REQUEST blocks so both backend and frontend agents read the same interface definition.
Output
api-contract.md containing all endpoint definitions with typed request/response schemas
- TypeScript interface declarations for
User, CreateUserRequest, LoginRequest, AuthResponse, ApiError, and domain-specific types
- Paginated response wrappers for list endpoints
- Standardized error format across all endpoints
Error Handling
| Error |
Cause |
Solution |
| Backend and frontend schemas diverge |
Contract updated without notifying both agents |
Always reference a single api-contract.md; never duplicate endpoint definitions |
| Missing error response codes |
Contract only documents the happy path |
Document all status codes: 400, 401, 403, 404, 409, 422 per endpoint |
| Ambiguous field types |
Using string without constraints |
Specify format, length, and validation rules (e.g., "string, required, min 8 chars") |
| Pagination inconsistency |
List endpoints use different parameter names |
Standardize on the PaginatedResponse<T> interface for all list endpoints |
| Type mismatch between JSON and TypeScript |
Dates serialized inconsistently |
Use ISO 8601 datetime strings; document as "createdAt": "ISO 8601 datetime" |
Examples
Authentication endpoint contract:
#### POST /auth/register
Create a new user account.
**Request:**
{
"email": "string (required, valid email)",
"password": "string (required, min 8 chars)",
"name": "string (optional)"
}
**Response (201):** # HTTP 201 Created
{
"id": "uuid",
"email": "string",
"name": "string | null",
"createdAt": "ISO 8601 datetime" # 8601 = configured value
}
**Errors:**
- 400: Invalid request body # HTTP 400 Bad Request
- 409: Email already exists # HTTP 409 Conflict
- 422: Validation failed # HTTP 422 Unprocessable Entity
Paginated list endpoint:
#### GET /products
List products with pagination.
**Query Parameters:**
| Param | Type | Default | Description |
|-------|------|---------|-------------|
| page | integer | 1 | Page number |
| limit | integer | 20 | Items per page (max 100) |
| sort | string | createdAt | Sort field |
| order | string | desc | Sort order (asc/desc) |
**Response (200):** # HTTP 200 OK
{
"data": [Product],
"pagination": { "page": 1, "limit": 20, "total": 150, "totalPages": 8 }
}
Shared TypeScript interface:
interface ApiError {
code: string;
message: string;
details?: Record<string, string[]>;
}
Resources
${CLAUDE_SKILL_DIR}/references/writing-endpoints.md -- Endpoint definition template and key elements
${CLAUDE_SKILL_DIR}/references/typescript-interfaces.md -- Canonical type definitions and guidelines
${CLAUDE_SKILL_DIR}/references/pagination.md -- Pagination parameters and PaginatedResponse interface
${CLAUDE_SKILL_DIR}/references/best-practices.md -- Contract authoring rules (specificity, DRY, no implementation details)
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: jeremylongshore-claude-code-plugins-plus-skills-api-contract3description: API Contract4---5# API Contract67## Overview89API Contract guides the creation of `api-contract.md` files that serve as the shared interface between backend and frontend agents during sprint execution. The contract defines request/response schemas, endpoint routes, TypeScript interfaces, and error formats so that implementation agents build to an agreed specification without direct coordination.1011## Prerequisites1213- Sprint directory initialized at `.claude/sprint/[N]/`14- `specs.md` with defined feature scope and endpoint requirements15- Familiarity with RESTful API conventions (HTTP methods, status codes, JSON schemas)16- TypeScript knowledge for interface definitions (recommended)1718## Instructions19201. Create `api-contract.md` in the sprint directory (`.claude/sprint/[N]/api-contract.md`). Define each endpoint using the standard format: HTTP method, route path, description, request body, response body with status code, and error codes. See `${CLAUDE_SKILL_DIR}/references/writing-endpoints.md` for the full template.212. Define TypeScript interfaces for all request and response types. Use explicit types instead of `any`, mark optional fields with `?`, and use `string | null` for nullable values. Reference `${CLAUDE_SKILL_DIR}/references/typescript-interfaces.md` for canonical type patterns.223. For list endpoints, include pagination parameters and the `PaginatedResponse<T>` wrapper. Standardize on `page`, `limit`, `sort`, and `order` query parameters as documented in `${CLAUDE_SKILL_DIR}/references/pagination.md`.234. Document all response states: success (200, 201, 204), client errors (400, 401, 403, 404, 422), and empty states. Use a consistent error response format with `code`, `message`, and optional `details` fields.245. Follow best practices from `${CLAUDE_SKILL_DIR}/references/best-practices.md`: be specific about field constraints (e.g., "string, required, valid email format"), include request/response examples, reference shared types instead of duplicating, and omit implementation details (no database columns, framework names, or file paths).256. Share the contract file path in SPAWN REQUEST blocks so both backend and frontend agents read the same interface definition.2627## Output2829- `api-contract.md` containing all endpoint definitions with typed request/response schemas30- TypeScript interface declarations for `User`, `CreateUserRequest`, `LoginRequest`, `AuthResponse`, `ApiError`, and domain-specific types31- Paginated response wrappers for list endpoints32- Standardized error format across all endpoints3334## Error Handling3536| Error | Cause | Solution |37|-------|-------|----------|38| Backend and frontend schemas diverge | Contract updated without notifying both agents | Always reference a single `api-contract.md`; never duplicate endpoint definitions |39| Missing error response codes | Contract only documents the happy path | Document all status codes: 400, 401, 403, 404, 409, 422 per endpoint |40| Ambiguous field types | Using `string` without constraints | Specify format, length, and validation rules (e.g., "string, required, min 8 chars") |41| Pagination inconsistency | List endpoints use different parameter names | Standardize on the `PaginatedResponse<T>` interface for all list endpoints |42| Type mismatch between JSON and TypeScript | Dates serialized inconsistently | Use ISO 8601 datetime strings; document as `"createdAt": "ISO 8601 datetime"` |4344## Examples4546**Authentication endpoint contract:**47```markdown48#### POST /auth/register4950Create a new user account.5152**Request:**53{54 "email": "string (required, valid email)",55 "password": "string (required, min 8 chars)",56 "name": "string (optional)"57}5859**Response (201):** # HTTP 201 Created60{61 "id": "uuid",62 "email": "string",63 "name": "string | null",64 "createdAt": "ISO 8601 datetime" # 8601 = configured value65}6667**Errors:**68- 400: Invalid request body # HTTP 400 Bad Request69- 409: Email already exists # HTTP 409 Conflict70- 422: Validation failed # HTTP 422 Unprocessable Entity71```7273**Paginated list endpoint:**74```markdown75#### GET /products7677List products with pagination.7879**Query Parameters:**80| Param | Type | Default | Description |81|-------|------|---------|-------------|82| page | integer | 1 | Page number |83| limit | integer | 20 | Items per page (max 100) |84| sort | string | createdAt | Sort field |85| order | string | desc | Sort order (asc/desc) |8687**Response (200):** # HTTP 200 OK88{89 "data": [Product],90 "pagination": { "page": 1, "limit": 20, "total": 150, "totalPages": 8 }91}92```9394**Shared TypeScript interface:**95```typescript96interface ApiError {97 code: string;98 message: string;99 details?: Record<string, string[]>;100}101```102103## Resources104105- `${CLAUDE_SKILL_DIR}/references/writing-endpoints.md` -- Endpoint definition template and key elements106- `${CLAUDE_SKILL_DIR}/references/typescript-interfaces.md` -- Canonical type definitions and guidelines107- `${CLAUDE_SKILL_DIR}/references/pagination.md` -- Pagination parameters and PaginatedResponse interface108- `${CLAUDE_SKILL_DIR}/references/best-practices.md` -- Contract authoring rules (specificity, DRY, no implementation details)109110---111> Converted and distributed by [TomeVault](https://tomevault.io/claim/jeremylongshore) — claim your Tome and manage your conversions.112<!-- tomevault:4.0:skill_md:2026-04-11 -->