Skip to content

cooper/api ​

ts
import { api } from "cooper-stack/api";

api(config, handler) ​

Define an API endpoint.

Config ​

FieldTypeDefaultDescription
methodstring"GET"HTTP method
pathstringrequiredURL path with :param placeholders
authbooleanfalseRequire authentication
validateZodSchema—Request body validation schema
stream"sse" | "websocket"—Enable streaming
middlewareMiddlewareFn[][]Per-route middleware

Handler ​

ts
async (input: T, principal?: P) => Promise<R>
  • input — merged path params + request body (validated if schema provided)
  • principal — auth principal (only when auth: true)
  • Return value is serialized as JSON

Apache-2.0 Licensed