API Reference: Context (ctx)

The Context object (ctx) is passed to every Jetpath route handler and middleware function. It serves as the primary interface for interacting with the request, constructing the response, and accessing framework features.

(This reference is based on the ContextType interface provided previously and examples in tests/app.jet.ts)

Interface Signature

interface ContextType<
  JetData extends {
    body?: Record<string, any>;
    params?: Record<string, any>;
    query?: Record<string, any>;
  },
  JetPluginTypes extends Record<string, unknown>[]
> {
  // Properties
  app: {};
  plugins: UnionToIntersection<JetPluginTypes[number]> & Record<string, any>;
  body: JetData["body"];
  query: JetData["query"];
  params: JetData["params"];
  connection: jet_socket; // WebSocket connection object
  request: Request; // Standard Request object
  code: number; // HTTP status code
  path: string; // Request pathname

// Methods eject(): never; validate(data?: any): JetData["body"]; // Type might vary based on usage sendStream(stream: any | string, ContentType: string): never; sendResponse(response?: Response): never; send(data: unknown, ContentType?: string): never; throw(codeOrData?: number | string | Record<string, any> | unknown, message?: string | Record<string, any>): never; redirect(url: string, code?: number): never; // Assuming optional code get(field: string): string | undefined; set(field: string, value: string): void; json(): Promise<Record<string, any>>;

// Internal Properties (Likely not for direct use) _1?: string | undefined; _2?: Record<string, string>; _3?: any; // Stream? _4?: boolean | undefined; _5?: (() => never) | undefined; _6?: Response | false; }

Properties Reference

Methods Reference

(Methods returning never terminate the request flow)

(For more detailed examples and usage context, please refer to the Core Concepts: Context page.)