Skip to content

Shokupan

Defined in: src/shokupan.ts:114

Shokupan Application

The main application class for creating a Shokupan web server.

The shape of ctx.state for all routes in the application. Use this to provide type safety for state management across middleware and handlers.

const app = new Shokupan();
app.get('/hello', (ctx) => ctx.json({ message: 'Hello' }));
await app.listen(3000);
interface AppState {
userId: string;
tenant: string;
requestId: string;
}
const app = new Shokupan<AppState>();
// Middleware has typed state access
app.use((ctx, next) => {
ctx.state.userId = 'user-123'; // ✓ Type-safe
ctx.state.requestId = crypto.randomUUID();
return next();
});
// Handlers have typed state access
app.get('/profile', (ctx) => {
const { userId, tenant } = ctx.state; // ✓ TypeScript knows these exist
return ctx.json({ userId, tenant });
});
import { EmptyState } from 'shokupan';
const app = new Shokupan<EmptyState>();
// ctx.state will be an empty object with no properties
interface RequestState {
userId: string;
permissions: string[];
}
const app = new Shokupan<RequestState>();
app.get('/users/:userId/posts/:postId', (ctx) => {
// Both params and state are fully typed!
const { userId, postId } = ctx.params; // ✓ Path params typed
const { permissions } = ctx.state; // ✓ State typed
return ctx.json({ userId, postId, permissions });
});

T extends Record<string, any> = GlobalShokupanState

new Shokupan<T>(applicationConfig): Shokupan<T>

Defined in: src/shokupan.ts:147

ShokupanConfig = {}

Shokupan<T>

ShokupanRouter.constructor

[$childControllers]: ShokupanController[] = []

Defined in: src/router.ts:101

ShokupanRouter.[$childControllers]


[$childRouters]: ShokupanRouter<T>[] = []

Defined in: src/router.ts:100

ShokupanRouter.[$childRouters]


[$mountPath]: string = "/"

Defined in: src/router.ts:97

ShokupanRouter.[$mountPath]


[$routes]: ShokupanRoute[] = []

Defined in: src/router.ts:146

ShokupanRouter.[$routes]


readonly applicationConfig: ShokupanConfig = {}

Defined in: src/shokupan.ts:115


optional asyncApiSpec: any

Defined in: src/shokupan.ts:117


readonly optional config: object

Defined in: src/router.ts:297

optional autoBackpressureFeedback: boolean

Whether to enable automatic backpressure based on system CPU load.

false

optional autoBackpressureLevel: number

The CPU usage percentage threshold (0-100) at which to start rejecting requests.

optional fileAccessCheck: (ctx, path) => boolean

Custom file access check for routes that use ctx.file(). Return true to allow access to the file, false to deny.

ShokupanContext

string

boolean

optional group: string

optional hooks: { afterValidate?: (ctx, data) => void | Promise<void>; beforeValidate?: (ctx, data) => void | Promise<void>; onError?: (ctx, error) => void | Promise<void>; onReadTimeout?: (ctx) => void | Promise<void>; onRequestEnd?: (ctx) => void | Promise<void>; onRequestStart?: (ctx) => void | Promise<void>; onRequestTimeout?: (ctx) => void | Promise<void>; onResponseEnd?: (ctx, response) => void | Promise<void>; onResponseStart?: (ctx, response) => void | Promise<void>; onStop?: () => void | Promise<void>; onWriteTimeout?: (ctx) => void | Promise<void>; } | ({ afterValidate?: (ctx, data) => void | Promise<void>; beforeValidate?: (ctx, data) => void | Promise<void>; onError?: (ctx, error) => void | Promise<void>; onReadTimeout?: (ctx) => void | Promise<void>; onRequestEnd?: (ctx) => void | Promise<void>; onRequestStart?: (ctx) => void | Promise<void>; onRequestTimeout?: (ctx) => void | Promise<void>; onResponseEnd?: (ctx, response) => void | Promise<void>; onResponseStart?: (ctx, response) => void | Promise<void>; onStop?: () => void | Promise<void>; onWriteTimeout?: (ctx) => void | Promise<void>; } | undefined)[]

Hooks for this route/router.

optional name: string

optional openapi: {[key: `x-${string}`]: any; [key: string]: any; consumes?: (string | undefined)[]; deprecated?: boolean; description?: string; externalDocs?: {[key: string]: any; description?: string; url?: string; }; operationId?: string; parameters?: ({[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: string]: any; description?: string; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; } | {[key: string]: any; $ref?: string; allowEmptyValue?: boolean; collectionFormat?: string; default?: any; description?: string; enum?: any[]; exclusiveMaximum?: boolean; exclusiveMinimum?: boolean; format?: string; in?: ParameterLocation; items?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | { $ref?: … | …; collectionFormat?: … | …; default?: any; enum?: … | …; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { type?: string | undefined; format?: string | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | undefined; … 14 more …; $ref?: string | undefined; } | undefined; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; multipleOf?: … | …; pattern?: … | …; type?: … | …; uniqueItems?: … | … | …; }; maximum?: number; maxItems?: number; maxLength?: number; minimum?: number; minItems?: number; minLength?: number; multipleOf?: number; name?: string; pattern?: string; required?: boolean; type?: string; uniqueItems?: boolean; } | undefined)[]; produces?: (string | undefined)[]; responses?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; description?: string; examples?: {[key: string]: any; }; headers?: {[key: string]: … | …; }; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; } | undefined; default?: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; description?: string; examples?: {[key: string]: any; }; headers?: {[key: string]: … | …; }; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; }; }; schemes?: (string | undefined)[]; security?: ({[key: string]: (… | …)[] | undefined; } | undefined)[]; summary?: string; tags?: (string | undefined)[]; } | {[key: `x-${string}`]: any; [key: string]: any; callbacks?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: string]: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; delete?: … | …; description?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; servers?: … | …; summary?: … | …; trace?: … | …; } | undefined; } | undefined; }; deprecated?: boolean; description?: string; externalDocs?: { description?: string; url?: string; }; operationId?: string; parameters?: ({[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | { allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | undefined)[]; requestBody?: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | { content?: {[key: string]: { encoding?: … | …; example?: any; examples?: … | …; schema?: … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; content?: {[key: string]: … | …; }; description?: string; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; } | undefined; }; security?: ({[key: string]: (… | …)[] | undefined; } | undefined)[]; servers?: ({ description?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; summary?: string; tags?: (string | undefined)[]; } | {[key: string]: any; [key: number]: any; callbacks?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: string]: any; [key: number]: any; delete?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; servers?: … | …; trace?: … | …; } | undefined; } | undefined; }; parameters?: ({ allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | undefined)[]; requestBody?: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { content?: {[key: string]: { encoding?: … | …; example?: any; examples?: … | …; schema?: … | … | … | … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: any; [key: number]: any; content?: {[key: string]: … | …; }; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; } | undefined; }; servers?: ({ description?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; } | {[key: string]: any; [key: number]: any; callbacks?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: string]: any; [key: number]: any; additionalOperations?: … | …; delete?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; query?: … | …; trace?: … | …; } | undefined; } | undefined; }; parameters?: ({[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; valueOf?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; valueOf?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; items?: { [x: string]: any; [x: number]: any; summary?: string | undefined; description?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { …; } | { …; } | { …; } | un…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; items?: { [x: string]: any; [x: number]: any; summary?: string | undefined; description?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { …; } | { …; } | { …; } | un…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | undefined)[]; requestBody?: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { content?: {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | { encoding?: … | …; example?: any; examples?: … | …; itemEncoding?: … | …; itemSchema?: … | … | … | … | … | … | …; prefixEncoding?: … | …; schema?: … | … | … | … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: any; [key: number]: any; content?: {[key: string]: … | … | …; }; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; summary?: string; } | undefined; }; servers?: ({ description?: string; name?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; }

optional renderer: JSXRenderer

Custom renderer for this route.

optional requestTimeout: number

Timeout for this specific route (milliseconds).

ShokupanRouter.config


optional dbPromise: Promise<any>

Defined in: src/shokupan.ts:125


mcpProtocol: McpProtocol

Defined in: src/router.ts:150

ShokupanRouter.mcpProtocol


optional metadata: RouteMetadata

Defined in: src/router.ts:148

ShokupanRouter.metadata


middleware: Middleware[] = []

Defined in: src/router.ts:133

ShokupanRouter.middleware


optional openApiSpec: any

Defined in: src/shokupan.ts:116


optional requestTimeout: number

Defined in: src/router.ts:126

ShokupanRouter.requestTimeout


responseTransformerRegistry: ResponseTransformerRegistry

Defined in: src/shokupan.ts:126


optional server: Server<any>

Defined in: src/shokupan.ts:122

get db(): DatastoreAdapter | undefined

Defined in: src/shokupan.ts:139

DatastoreAdapter | undefined


get hasAfterValidateHook(): boolean

Defined in: src/router.ts:124

boolean

ShokupanRouter.hasAfterValidateHook


get hasBeforeValidateHook(): boolean

Defined in: src/router.ts:123

boolean

ShokupanRouter.hasBeforeValidateHook


get hasOnErrorHook(): boolean

Defined in: src/router.ts:119

boolean

ShokupanRouter.hasOnErrorHook


get hasOnReadTimeoutHook(): boolean

Defined in: src/router.ts:121

boolean

ShokupanRouter.hasOnReadTimeoutHook


get hasOnRequestEndHook(): boolean

Defined in: src/router.ts:117

boolean

ShokupanRouter.hasOnRequestEndHook


get hasOnRequestStartHook(): boolean

Defined in: src/router.ts:116

boolean

ShokupanRouter.hasOnRequestStartHook


get hasOnRequestTimeoutHook(): boolean

Defined in: src/router.ts:120

boolean

ShokupanRouter.hasOnRequestTimeoutHook


get hasOnResponseEndHook(): boolean

Defined in: src/router.ts:115

boolean

ShokupanRouter.hasOnResponseEndHook


get hasOnResponseStartHook(): boolean

Defined in: src/router.ts:118

boolean

ShokupanRouter.hasOnResponseStartHook


get hasOnStopHook(): boolean

Defined in: src/router.ts:114

boolean

ShokupanRouter.hasOnStopHook


get hasOnWriteTimeoutHook(): boolean

Defined in: src/router.ts:122

boolean

ShokupanRouter.hasOnWriteTimeoutHook


get logger(): Logger | undefined

Defined in: src/shokupan.ts:143

Logger | undefined

ShokupanRouter.logger


get registry(): object

Defined in: src/router.ts:208

object

controllers: object[]

events: object[]

metadata: RouteMetadata | undefined

middleware: object[]

routers: object[]

routes: object[]

ShokupanRouter.registry


get root(): Shokupan<any>

Defined in: src/router.ts:138

Shokupan<any>

ShokupanRouter.root


get rootConfig(): Partial<{ adapter?: ServerAdapter | "bun" | "node" | "wintercg"; aiPlugin?: { api?: { is_user_authenticated?: boolean; type: "openapi"; url?: string; }; auth?: {[key: string]: any; type: "none" | "service_http" | "user_http" | "oauth"; }; contact_email?: string; description_for_human?: string; description_for_model?: string; enabled?: boolean; legal_info_url?: string; logo_url?: string; name_for_human?: string; name_for_model?: string; }; allowChunkedBody?: boolean; allowedStaticFilePaths?: string[]; apiCatalog?: { enabled?: boolean; versions?: object[]; }; astAnalysisTimeout?: number; astFilePath?: string; autoBackpressureFeedback?: boolean; autoBackpressureLevel?: number; blockOnAsyncApiGen: boolean; blockOnOpenApiGen: boolean; datastore?: { adapter: "surreal" | "sqlite" | "level"; options?: any; }; defaultResponseTransformer?: string; defaultSecurityHeaders?: any; development: boolean; disableBodyParsing?: boolean; enableAbortController?: boolean; enableAsyncApiGen: boolean; enableAsyncAstScanning?: boolean; enableAsyncLocalStorage: boolean; enableAutoContentNegotiation?: boolean; enableHTTPBridge?: boolean; enableMiddlewareTracking: boolean; enableOpenApiGen: boolean; enablePromiseMonkeypatch: boolean; enableTracing?: boolean; enableWebSocketTracking?: boolean; fileAccessCheck?: (ctx, path) => boolean; fileSystem?: FileSystemAdapter; hooks: ShokupanHooks<Record<string, any>> | ShokupanHooks<Record<string, any>>[]; hostname: string; httpLogger: (ctx) => void; ide?: string; idGenerator?: () => string; jsonParser?: "native" | "parse-json" | "secure-json-parse"; logger: Logger; maxBodySize?: number; middlewareTrackingMaxCapacity?: number; middlewareTrackingTTL?: number; port: number; queryParserMode?: "strict" | "extended" | "simple"; readTimeout: number; renderer: JSXRenderer; requestTimeout: number; reusePort: boolean; tls: {[key: string]: any; cert: string; key: string; }; validateStatusCodes: boolean; websocketErrorHandler?: (err, ctx) => void | Promise<void>; writeTimeout: number; }>

Defined in: src/router.ts:135

Partial<{ adapter?: ServerAdapter | "bun" | "node" | "wintercg"; aiPlugin?: { api?: { is_user_authenticated?: boolean; type: "openapi"; url?: string; }; auth?: {[key: string]: any; type: "none" | "service_http" | "user_http" | "oauth"; }; contact_email?: string; description_for_human?: string; description_for_model?: string; enabled?: boolean; legal_info_url?: string; logo_url?: string; name_for_human?: string; name_for_model?: string; }; allowChunkedBody?: boolean; allowedStaticFilePaths?: string[]; apiCatalog?: { enabled?: boolean; versions?: object[]; }; astAnalysisTimeout?: number; astFilePath?: string; autoBackpressureFeedback?: boolean; autoBackpressureLevel?: number; blockOnAsyncApiGen: boolean; blockOnOpenApiGen: boolean; datastore?: { adapter: "surreal" | "sqlite" | "level"; options?: any; }; defaultResponseTransformer?: string; defaultSecurityHeaders?: any; development: boolean; disableBodyParsing?: boolean; enableAbortController?: boolean; enableAsyncApiGen: boolean; enableAsyncAstScanning?: boolean; enableAsyncLocalStorage: boolean; enableAutoContentNegotiation?: boolean; enableHTTPBridge?: boolean; enableMiddlewareTracking: boolean; enableOpenApiGen: boolean; enablePromiseMonkeypatch: boolean; enableTracing?: boolean; enableWebSocketTracking?: boolean; fileAccessCheck?: (ctx, path) => boolean; fileSystem?: FileSystemAdapter; hooks: ShokupanHooks<Record<string, any>> | ShokupanHooks<Record<string, any>>[]; hostname: string; httpLogger: (ctx) => void; ide?: string; idGenerator?: () => string; jsonParser?: "native" | "parse-json" | "secure-json-parse"; logger: Logger; maxBodySize?: number; middlewareTrackingMaxCapacity?: number; middlewareTrackingTTL?: number; port: number; queryParserMode?: "strict" | "extended" | "simple"; readTimeout: number; renderer: JSXRenderer; requestTimeout: number; reusePort: boolean; tls: {[key: string]: any; cert: string; key: string; }; validateStatusCodes: boolean; websocketErrorHandler?: (err, ctx) => void | Promise<void>; writeTimeout: number; }>

ShokupanRouter.rootConfig

[$dispatch](req): Promise<Response | undefined>

Defined in: src/shokupan.ts:689

ShokupanRequest<T>

Promise<Response | undefined>


add(arg): Shokupan<T>

Defined in: src/router.ts:1160

Adds a route to the router.

Route configuration object

any

Controller for the route

string

Group for the route

ShokupanHandler<T>

Route handler function

{ file: string; line: number; }

string

number

Method

HTTP method

Middleware[]

string

URL path

RegExp

Custom regex for path matching

JSXRenderer

JSX renderer for the route

number

Timeout for this route in milliseconds

MethodAPISpec

OpenAPI specification for the route

Shokupan<T>

ShokupanRouter.add


bindController(controller): void

Defined in: src/router.ts:402

Registers a controller instance to the router.

any

void

ShokupanRouter.bindController


compile(): void

Defined in: src/shokupan.ts:1136

Compiles all routes into a master Trie for O(1) router lookup. Use this if adding routes dynamically after start (not recommended but possible).

void


delete<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1368

Adds a DELETE route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.delete

delete<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1376

Adds a DELETE route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.delete


fetch(req, server?): Promise<Response | undefined>

Defined in: src/shokupan.ts:762

Handles an incoming request (Bun.serve interface). This logic contains the middleware chain and router dispatch.

any

The request to handle.

Server<any>

The server instance.

Promise<Response | undefined>

The response to send.


find(method, path): { handler: ShokupanHandler<T>; params: Record<string, string>; route?: any; } | null

Defined in: src/shokupan.ts:1226

Find a route matching the given method and path. Wraps handler with router middleware if present.

string

HTTP method

string

Request path

{ handler: ShokupanHandler<T>; params: Record<string, string>; route?: any; } | null

Route handler and parameters if found, otherwise null

ShokupanRouter.find


findEvent(name): ShokupanHandler<T>[] | null

Defined in: src/router.ts:383

Finds an event handler(s) by name.

string

ShokupanHandler<T>[] | null

ShokupanRouter.findEvent


generateApiSpec(options): Promise<any>

Defined in: src/router.ts:1652

Generates an OpenAPI 3.1 Document by recursing through the router and its descendants. Now includes runtime analysis of handler functions to infer request/response types.

OpenAPIOptions = {}

Promise<any>

ShokupanRouter.generateApiSpec


get<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1308

Adds a GET route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.get

get<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1316

Adds a GET route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.get


getEventHandlers(): Map<string, ShokupanHandler<T>[]>

Defined in: src/router.ts:409

Returns all registered event handlers.

Map<string, ShokupanHandler<T>[]>

ShokupanRouter.getEventHandlers


getRoutes(): object[]

Defined in: src/router.ts:801

Returns all routes attached to this router and its descendants.

object[]

ShokupanRouter.getRoutes


guard(handler): void

Defined in: src/router.ts:1509

Adds a guard to the router that applies to all routes added after this point. Guards must return true or call ctx.next() to allow the request to continue.

ShokupanHandler<T>

Guard handler function

void

ShokupanRouter.guard

guard(spec, handler): void

Defined in: src/router.ts:1517

Adds a guard to the router that applies to all routes added after this point. Guards must return true or call ctx.next() to allow the request to continue.

GuardAPISpec

OpenAPI specification for the guard

ShokupanHandler<T>

Guard handler function

void

ShokupanRouter.guard


hasHooks(name): boolean

Defined in: src/router.ts:1657

keyof ShokupanHooks<any>

boolean

ShokupanRouter.hasHooks


head<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1428

Adds a HEAD route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.head

head<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1436

Adds a HEAD route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.head


hook(name, handler): Shokupan<T>

Defined in: src/router.ts:317

Registers a lifecycle hook dynamically.

keyof ShokupanHooks<any>

Function

Shokupan<T>

ShokupanRouter.hook


internalRequest(arg): Promise<Response | undefined>

Defined in: src/router.ts:833

Makes an internal request through this router’s full routing pipeline. This is useful for calling other routes internally and supports streaming responses.

string | { body?: any; headers?: HeadersInit; method?: Method; path: string; }

Promise<Response | undefined>

The raw Response object.

ShokupanRouter.internalRequest


listen(port?, callback?): Promise<Server<any> | undefined>

Defined in: src/shokupan.ts:633

Starts the application server.

number

The port to listen on. If not specified, the port from the configuration is used. If that is not specified, port 3000 is used.

() => void

Promise<Server<any> | undefined>

The server instance.


mount(prefix, controller): Shokupan<T>

Defined in: src/router.ts:423

Mounts a controller instance or WebSocket router to a path prefix.

Controller can be a convention router, WebSocket router, or an arbitrary class.

Routes are derived from method names:

  • get(ctx) -> GET /prefix/
  • getUsers(ctx) -> GET /prefix/users
  • postCreate(ctx) -> POST /prefix/create

string

Record<string, any> | ShokupanRouter<T> | ShokupanRouter<GlobalShokupanState> | ShokupanController | ShokupanController<T>

Shokupan<T>

ShokupanRouter.mount


onSpecAvailable(callback): Shokupan<T>

Defined in: src/shokupan.ts:421

Registers a callback to be executed when the OpenAPI spec is available. This happens after generateOpenApi() but before the server starts listening (or at least before it finishes startup if async).

(spec) => void | Promise<void>

Shokupan<T>


onStart(callback): Shokupan<T>

Defined in: src/shokupan.ts:412

Registers a callback to be executed before the server starts listening.

() => void | Promise<void>

Shokupan<T>


onStrictError<T>(type, handler): this

Defined in: src/shokupan.ts:276

Register a global error handler for a specific error type. Handlers are checked in reverse order of registration (LIFO).

T

(…args) => T

The error class constructor (e.g., Error, CustomError)

ErrorHandler<T>

The handler function

this


options<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1408

Adds a OPTIONS route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.options

options<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1416

Adds a OPTIONS route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.options


patch<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1388

Adds a PATCH route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.patch

patch<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1396

Adds a PATCH route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.patch


post<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1328

Adds a POST route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.post

post<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1336

Adds a POST route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.post


prompt(name, args, handler): Shokupan<T>

Defined in: src/router.ts:359

Registers an MCP Prompt.

string

object[] | undefined

Function

Shokupan<T>

ShokupanRouter.prompt


put<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1348

Adds a PUT route to the router.

Path extends string

Path

URL path

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.put

put<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1356

Adds a PUT route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<T, RouteParams<Path>>

ShokupanHandler<T, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.put


register(plugin, options?): Promise<Shokupan<T>>

Defined in: src/shokupan.ts:395

Registers a plugin. This returns a promise that resolves when the plugin is initialized. You do not need to await it unless you want to run code specifically after the plugin is initialized. Shokupan automatically awaits plugin initialization promises when calling listen().

ShokupanPlugin

string

Promise<Shokupan<T>>


registerResponseTransformer(transformer): this

Defined in: src/shokupan.ts:264

Register a custom response transformer

ResponseTransformer

The transformer to register

this


resource(uri, options, handler): Shokupan<T>

Defined in: src/router.ts:371

Registers an MCP Resource.

string

string

string

string

Function

Shokupan<T>

ShokupanRouter.resource


runHooks(name, …args): void | Promise<void[]>

Defined in: src/router.ts:1708

keyof ShokupanHooks<any>

any[]

void | Promise<void[]>

ShokupanRouter.runHooks


runOnStopHooks(app): Promise<void>

Defined in: src/router.ts:1749

Shokupan<any>

Promise<void>

ShokupanRouter.runOnStopHooks


setDefaultResponseType(contentType): this

Defined in: src/shokupan.ts:285

Set the default response transformer content type

string

The content type to use as default

this


socket<Path>(path, handler): this

Defined in: src/router.ts:1469

Adds a WebSocket route that handles its own upgrade logic.

Unless you need to handle the upgrade manually, you should use a ShokupanWebsocketRouter or WebsocketController instead.

Routes registered with .socket() will NOT be automatically upgraded by Shokupan’s WebSocket handling. You must implement all event handlers manually. You have been warned.

Path extends string

Path

URL path for the WebSocket endpoint

ShokupanHandler<T, RouteParams<Path>>

Route handler that will manually handle the upgrade

this

router.socket("/ws", (ctx) => {
const success = ctx.upgrade({
data: {
handler: {
open: (ws) => console.log("Connected"),
message: (ws, msg) => ws.send(msg),
close: (ws) => console.log("Disconnected")
}
}
});
if (!success) return ctx.text("Upgrade failed", 400);
});

ShokupanRouter.socket


start(): Promise<void>

Defined in: src/shokupan.ts:436

Prepare the application for listening. Use this if you want to initialize the app without starting the server immediately.

Promise<void>


static(uriPath, options): Shokupan<T>

Defined in: src/router.ts:1562

Statically serves a directory with standard options.

string

URL path prefix

Configuration options or root directory string

string | StaticServeOptions<T>

Shokupan<T>

ShokupanRouter.static


stop(closeActiveConnections?): Promise<void>

Defined in: src/shokupan.ts:668

Stops the application server.

This method gracefully shuts down the server and stops any running monitors.

boolean

— Immediately terminate in-flight requests, websockets, and stop accepting new connections.

Promise<void>

A promise that resolves when the server has been stopped.

const app = new Shokupan();
const server = await app.listen(3000);
// Later, when you want to stop the server
await app.stop();

testRequest(options): Promise<ProcessResult>

Defined in: src/shokupan.ts:696

Processes a request by wrapping the standard fetch method.

RequestOptions

Promise<ProcessResult>

ShokupanRouter.testRequest


tool(name, schema, handler): Shokupan<T>

Defined in: src/router.ts:347

Registers an MCP Tool.

string

any

Function

Shokupan<T>

ShokupanRouter.tool


use(middleware): this

Defined in: src/shokupan.ts:338

Adds middleware to the application.

Supports Express-style path-based middleware: use('/admin', middleware) runs only for routes under /admin.

Middleware

this

ShokupanRouter.use

use(path, middleware): this

Defined in: src/shokupan.ts:339

Adds middleware to the application.

Supports Express-style path-based middleware: use('/admin', middleware) runs only for routes under /admin.

string

Middleware

this

ShokupanRouter.use