TypeScript
To add coding intellisense to your editor, install the types package:
pnpm add kyushu-types -Dnpm install kyushu-types -Dyarn add kyushu-types -DExportedHandler
Section titled “ExportedHandler”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;WorkerRequest
Section titled “WorkerRequest”The incoming HTTP request passed to the fetch handler.
| Field | Type | Description |
|---|---|---|
method | WorkerMethod | HTTP method (GET, POST, etc.) |
url | string | Full request URL |
headers | Record<string, string> | undefined | Request headers |
body | string | ArrayBuffer | Uint8Array | undefined | Request body |
WorkerResponse
Section titled “WorkerResponse”The HTTP response returned by the fetch handler.
| Field | Type | Description |
|---|---|---|
status | number | undefined | HTTP status code (default: 200) |
body | string | ArrayBuffer | Uint8Array | undefined | Response body |
headers | Record<string, string> | undefined | Response headers |
The environment object passed as the second argument to the fetch handler.
| Field | Type | Description |
|---|---|---|
ASSETS | EnvAssets | Provides features to handle assets. |
EnvAssets
Section titled “EnvAssets”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.
| Method | Signature | Description |
|---|---|---|
fetch | (request: WorkerRequest, options?: AssetFetchOptions) => Promise<WorkerResponse> | Serve a static asset. Defaults to handling assets from "memory". |
AssetFetchOptions
Section titled “AssetFetchOptions”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.
| Field | Type | Description |
|---|---|---|
src | "memory" | "fs" | The source to fetch assets from. |
WorkerMethod
Section titled “WorkerMethod”type WorkerMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";Runtime validation
Section titled “Runtime validation”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";