Skip to main content
This release is 6 versions behind 17.1.3 — the latest version of @oak/oak. Jump to latest

@oak/oak@16.0.0
Built and signed on GitHub Actions

A middleware framework for handling HTTP with Deno, Node.js, Bun and Cloudflare Workers 🐿️🦕🥟⚙️

This package works with Cloudflare Workers, Node.js, Deno, Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
7 months ago (16.0.0)
class Request

An interface which provides information about the current request. The instance related to the current request is available on the Context's .request property.

The interface contains several properties to get information about the request as well as several methods, which include content negotiation and the ability to decode a request body.

Constructors

new
Request(
serverRequest: ServerRequest,
unnamed 1?: OakRequestOptions,
)

Properties

readonly
body: Body

An interface to access the body of the request. This provides an API that aligned to the Fetch Request API, but in a dedicated API.

readonly
hasBody: boolean

Is true if the request might have a body, otherwise false.

WARNING this is an unreliable API. In HTTP/2 in many situations you cannot determine if a request has a body or not unless you attempt to read the body, due to the streaming nature of HTTP/2. As of Deno 1.16.1, for HTTP/1.1, Deno also reflects that behaviour. The only reliable way to determine if a request has a body or not is to attempt to read the body.

readonly
headers: Headers

The Headers supplied in the request.

readonly
ip: string

Request remote address. When the application's .proxy is true, the X-Forwarded-For will be used to determine the requesting remote address.

readonly
ips: string[]

When the application's .proxy is true, this will be set to an array of IPs, ordered from upstream to downstream, based on the value of the header X-Forwarded-For. When false an empty array is returned.

readonly
method: HTTPMethods

The HTTP Method used by the request.

deprecated
readonly
originalRequest: ServerRequest

Set to the value of the low level oak server request abstraction.

readonly
secure: boolean

Shortcut to request.url.protocol === "https:".

readonly
source: globalThis.Request | undefined

Returns the original Fetch API Request if available.

This should be set with requests on Deno, but will not be set when running on Node.js.

readonly
url: URL

A parsed URL for the request which complies with the browser standards. When the application's .proxy is true, this value will be based off of the X-Forwarded-Proto and X-Forwarded-Host header values if present in the request.

readonly
userAgent: UserAgent

An object representing the requesting user agent. If the User-Agent header isn't defined in the request, all the properties will be undefined.

See std/http/user_agent#UserAgent for more information.

Methods

[Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string): string
[Symbol.for("nodejs.util.inspect.custom")](
depth: number,
options: any,
inspect: (
value: unknown,
options?: unknown,
) => string
,
): any
accepts(): string[] | undefined

Returns an array of media types, accepted by the requestor, in order of preference. If there are no encodings supplied by the requestor, then accepting any is implied is returned.

accepts(...types: string[]): string | undefined

For a given set of media types, return the best match accepted by the requestor. If there are no encoding that match, then the method returns undefined.

acceptsEncodings(): string[] | undefined

Returns an array of encodings, accepted by the requestor, in order of preference. If there are no encodings supplied by the requestor, then ["*"] is returned, matching any.

acceptsEncodings(...encodings: string[]): string | undefined

For a given set of encodings, return the best match accepted by the requestor. If there are no encodings that match, then the method returns undefined.

NOTE: You should always supply identity as one of the encodings to ensure that there is a match when the Accept-Encoding header is part of the request.

acceptsLanguages(): string[] | undefined

Returns an array of languages, accepted by the requestor, in order of preference. If there are no languages supplied by the requestor, ["*"] is returned, indicating any language is accepted.

acceptsLanguages(...langs: string[]): string | undefined

For a given set of languages, return the best match accepted by the requestor. If there are no languages that match, then the method returns undefined.

sendEvents(
options?: ServerSentEventTargetOptions,
init?: RequestInit,
): Promise<ServerSentEventTarget>

Take the current request and initiate server sent event connection.

![WARNING] This is not intended for direct use, as it will not manage the target in the overall context or ensure that additional middleware does not attempt to respond to the request.

upgrade(options?: UpgradeWebSocketOptions): WebSocket

Take the current request and upgrade it to a web socket, returning a web standard WebSocket object.

If the underlying server abstraction does not support upgrades, this will throw.

![WARNING] This is not intended for direct use, as it will not manage the websocket in the overall context or ensure that additional middleware does not attempt to respond to the request.

Add Package

deno add jsr:@oak/oak

Import symbol

import { Request } from "@oak/oak/request";

---- OR ----

Import directly with a jsr specifier

import { Request } from "jsr:@oak/oak/request";

Add Package

npx jsr add @oak/oak

Import symbol

import { Request } from "@oak/oak/request";

Add Package

yarn dlx jsr add @oak/oak

Import symbol

import { Request } from "@oak/oak/request";

Add Package

pnpm dlx jsr add @oak/oak

Import symbol

import { Request } from "@oak/oak/request";

Add Package

bunx jsr add @oak/oak

Import symbol

import { Request } from "@oak/oak/request";