← ClaudeAtlas

api-designerlisted

Type-safe API design: Zod validation, Result types, SvelteKit endpoints, middleware patterns.
JasonWarrenUK/goblin-mode · ★ 5 · API & Backend · score 73
Install: claude install-skill JasonWarrenUK/goblin-mode
# TypeScript API Design Comprehensive guide to designing type-safe APIs with TypeScript. Covers type-safe contracts, validation with Zod, Result types for error handling, SvelteKit endpoints, middleware patterns, and API versioning. ## When This Skill Applies Use this skill when: - Designing API endpoints - Creating type-safe API contracts - Implementing validation - Handling API errors - Building SvelteKit API routes - Creating reusable middleware - Versioning APIs - Questions about API design patterns ## Type-Safe Contracts ### Request/Response Types ```typescript // types/api.ts export interface CreateUserRequest { email: string; name: string; password: string; } export interface User { id: string; email: string; name: string; createdAt: string; } export interface ApiError { code: string; message: string; details?: Record<string, string[]>; } ``` **Key principle**: Types ARE documentation. Well-named types with clear structure tell the story. ### Result Type Pattern ```typescript // For expected failures (not found, validation, etc.) export type Result<T, E = string> = | { success: true; data: T } | { success: false; error: E }; // Usage function findUser(id: string): Result<User, 'not_found'> { const user = db.findUser(id); if (!user) { return { success: false, error: 'not_found' }; } return { success: true, data: user }; } // Consuming const result = findUser('123'); if (result.success) { console.log(result.data.email); // Type-safe access }