@whi/cf-routing - v0.7.0
    Preparing search index...

    Class DurableObjectRouteHandler<E, P, D>Abstract

    Base class for route handlers in DurableObjectRouter

    Extend this class to create handlers for Durable Object routes with access to storage and environment. The handler instance has access to this.storage, this.id, this.state, and this.env. By default, all HTTP methods throw a 405 Method Not Allowed error. Override the methods you want to support.

    Response customization:

    • Use ctx.response to modify status, statusText, or headers before returning data
    • Return a Response object directly for full control
    • Return plain data for default JSON serialization
    class CounterHandler extends DurableObjectRouteHandler<Env> {
    async get(ctx) {
    const count = await this.storage.get<number>('count') || 0;
    return { count };
    }

    async post(ctx) {
    const current = await this.storage.get<number>('count') || 0;
    await this.storage.put('count', current + 1);
    ctx.response.status = 201;
    return { count: current + 1 };
    }
    }

    Type Parameters

    • E extends Env = Env

      Environment type

    • P extends Params = Params

      Route parameters type

    • D = Record<string, any>

      Data type for middleware-set data

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    path: string
    log: Logger
    state: DurableObjectState

    The raw DurableObjectState - use for blockConcurrencyWhile, etc.

    storage: DurableObjectStorage

    Flattened storage access from DurableObjectState

    id: DurableObjectId

    Flattened ID access from DurableObjectState

    env: E

    Environment bindings

    Methods

    post