src/orchestrator/skills/api-patterns/SKILL.md
Creates API route handlers, implements Server Actions with Zod schema validation, integrates external REST APIs with error handling. Use when adding endpoints, building request handlers, or wiring external services (endpoint, REST API, request handling, fetch, .ts route files).
npx skillsauth add monkilabs/opencastle api-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Project-specific config: api-config.md.
| Layer | Use for |
|-------|---------|
| Server Actions (preferred) | mutations, form submissions, data writes, auth |
| Route Handlers (route.ts) | analytics, autocomplete, external integrations |
| Proxy layer | IP rate limiting, fingerprinting, bot detection |
// app/api/example/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
const schema = z.object({ query: z.string().min(1).max(200) });
export async function GET(request: NextRequest) {
const result = schema.safeParse(Object.fromEntries(request.nextUrl.searchParams));
if (!result.success) return NextResponse.json({ error: 'Invalid input' }, { status: 400 });
return NextResponse.json(data);
}
import fetch from 'node-fetch';
async function fetchWithRetry(url:string, opts={}, retries=2){
for(let i=0;i<=retries;i++){
try{ const res = await fetch(url, opts); if(!res.ok) throw new Error(`HTTP ${res.status}`); return await res.json(); }
catch(e){ if(i===retries) throw e; await new Promise(r=>setTimeout(r, 500*(i+1))); }
}
}
// usage
const data = await fetchWithRetry('https://api.example.com/data');
### Server Action
```typescript
'use server';
import { createServerClient } from '@libs/auth';
import { revalidatePath } from 'next/cache';
export async function submitAction(formData: FormData) {
const { data: { user } } = await (await createServerClient()).auth.getUser();
if (!user) return { error: 'Unauthorized' };
revalidatePath('/places');
return { success: true };
}
app/api/<name>/route.ts or app/<segment>/route.tscurl -fsS "http://localhost:3000/api/<name>?query=test" || (echo "route failed" && exit 1)
/api/v1/places/:slug; HTTP methods: GET read, POST create, PATCH update, DELETE remove{ "data": ..., "meta": { "total": 42, "page": 1 } }{ "error": { "code": "VALIDATION_ERROR", "message": "...", "details": [...] } }limit, cursor, sort, order/api/v1/...; add fields only, never remove/rename; deprecation headers before removalCache-Control, ETag/If-None-Match headersdevelopment
Defines 10 sequential validation gates: secret scanning, lint/test/build checks, blast radius analysis, dependency auditing, browser testing, cache management, regression checks, smoke tests. Use when running pre-deploy validation or CI checks, CI/CD pipelines, deployment pipeline validation, pre-merge checks, continuous integration, or pull request validation.
development
Generates test plans, writes unit/integration/E2E test files, identifies coverage gaps, flags common testing anti-patterns. Use when writing tests, creating test suites, planning test strategies, mocking dependencies, measuring code coverage, or test planning.
development
Provides model routing rules, validates delegation prerequisites, supplies cost tracking templates, defines dead-letter queue formats for Team Lead orchestration. Load when assigning tasks to agents, choosing model tiers, starting delegation session, running multi-agent workflow, delegating work, choosing which model to use, or assigning tasks.
testing
Saves, restores session state including task progress, file changes, delegation history. Use when saving progress, resuming interrupted work, picking up where you left off, or checkpointing current work.