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

    Class DurableObjectRouteHandler<E, P>Abstract

    Base class for route handlers in DurableObjectRouter

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

    Response customization:

    • Use this.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() {
    const count = await this.ctx.storage.get<number>('count') || 0;
    return { count };
    }

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

    Type Parameters

    • E extends Env

      Environment type

    • P extends Params = Params

      Route parameters type

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    path: string
    ctx: DurableObjectState
    env: E
    log: Logger
    response: ResponseContext

    Response context for customizing the response. Modify status, statusText, or headers before returning data.

    this.response.status = 201;
    this.response.headers.set('Set-Cookie', 'session=abc123');
    return { created: true };

    Methods

    • Parameters

      • request: Request
      • Optionalparams: P

      Returns Promise<any>

    post

    • post(request: Request, params?: P): Promise<any>

      Parameters

      • request: Request
      • Optionalparams: P

      Returns Promise<any>

    • Parameters

      • request: Request
      • Optionalparams: P

      Returns Promise<any>

    • Parameters

      • request: Request
      • Optionalparams: P

      Returns Promise<any>

    • Parameters

      • request: Request
      • Optionalparams: P

      Returns Promise<any>