Class WayRequest

Decorates the incoming Request with routing and parsing helpers.

app.post("/echo", async (ctx) => {
const body = await ctx.req.parseBody();
console.log(ctx.req.headers.get("content-type"));
return ctx.res.json({ received: body });
});

Constructors

Properties

_bodyParseError: null | BodyParseErrorState = null
_bodyParsed: boolean = false
_bodyType: null | ParsedBodyType = null
_rawBody: null | Uint8Array = null
_rawText: null | string = null
bodyParserDefaults: ResolvedBodyParserOptions
bodyParserOverrides: null | BodyParserOptions = null
bodyValue: any = null
localsStore: Record<string, any> = {}
originalRequest: Request
paramsStore: Record<string, string> = {}
parsedUrl: URL

Accessors

  • get bodyParseError(): null | BodyParseErrorState
  • Returns null | BodyParseErrorState

  • get locals(): Record<string, any>
  • Shared per-request state bag useful for communication between middleware.

    Returns Record<string, any>

  • get params(): Record<string, string>
  • Snapshot of current route params (mutable on purpose for express parity).

    Returns Record<string, string>

  • set params(value): void
  • Allows the router or middleware to replace params in one go.

    Parameters

    • value: Record<string, string>

    Returns void

  • get path(): string
  • Alias for pathname for those used to Express' req.path.

    Returns string

  • get pathname(): string
  • Path segment (no query string). Equivalent to new URL(req.url).pathname.

    Returns string

  • get query(): URLSearchParams
  • Live URLSearchParams view of the request query.

    Returns URLSearchParams

  • get search(): string
  • Raw query string portion (including leading ?).

    Returns string

Methods

  • Parameters

    • config: ResolvedBodyParserOptions

    Returns Promise<void>

  • Returns ResolvedBodyParserOptions

  • True when a body parser (auto or manual) already produced a result.

    Returns boolean

  • Convenience helper mirroring Express' req.param(name) lookup.

    Parameters

    • key: string

    Returns undefined | string

  • Lazy-load the request body as bytes. Cached so multiple calls are cheap.

    Returns Promise<Uint8Array>

  • Parameters

    • status: number
    • message: string

    Returns void

  • Persist successful parsing state. Called by the individual parser helpers.

    Parameters

    • value: any
    • type: ParsedBodyType

    Returns void

  • Parameters

    • options: Required<Required<JsonParserOptions>>

    Returns Promise<boolean>

  • Parameters

    • options: Required<Required<TextParserOptions>>

    Returns Promise<boolean>

  • Parameters

    • options: Required<Required<UrlencodedParserOptions>>

    Returns Promise<boolean>