Skip to content

TypeScript

To add coding intellisense to your editor, install the types package:

Terminal window
pnpm add kyushu-types -D

The default export shape expected by Kyushu workers.

import type { ExportedHandler } from "kyushu-types";
export default {
async fetch(request, env) {
return {
status: 200,
body: "Hello, world!",
};
},
} satisfies ExportedHandler;

The incoming HTTP request passed to the fetch handler.

FieldTypeDescription
methodWorkerMethodHTTP method (GET, POST, etc.)
urlstringFull request URL
headersRecord<string, string> | undefinedRequest headers
bodystring | ArrayBuffer | Uint8Array | undefinedRequest body

The HTTP response returned by the fetch handler.

FieldTypeDescription
statusnumber | undefinedHTTP status code (default: 200)
bodystring | ArrayBuffer | Uint8Array | undefinedResponse body
headersRecord<string, string> | undefinedResponse headers

The environment object passed as the second argument to the fetch handler.

FieldTypeDescription
ASSETSEnvAssetsProvides features to handle assets.

Provides access to static assets bundled into the worker at build time or read from mounted file system. See the Static Assets guide for the instructions to set up the former.

MethodSignatureDescription
fetch(request: WorkerRequest, options?: AssetFetchOptions) => Promise<WorkerResponse>Serve a static asset. Defaults to handling assets from "memory".

The default approach to serve static asset is bundling and serving them to memory. But you might need to read those from the file-system, notably if you hit some memory limitation when bundling the worker.

FieldTypeDescription
src"memory" | "fs"The source to fetch assets from.
type WorkerMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";

The worker validates both the incoming request and outgoing response using Zod schemas at the Wasm boundary. If your handler returns an unexpected shape, you get a clear error rather than a silent failure.

The schemas are also exported from kyushu-types if you need them directly:

import { WorkerRequestSchema, WorkerResponseSchema, ExportedHandlerSchema } from "kyushu-types";