Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Body

import { Body } from "https://raw.githubusercontent.com/oakserver/oak/master/body.ts";

An object which encapsulates information around a request body.

class Body {
constructor(serverRequest: Pick<ServerRequest, "request" | "headers" | "getBody">, reviver?: JsonReviver);
get has(): boolean;
get stream(): ReadableStream<Uint8Array> | null;
get used(): boolean;
 
async arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
async form(): Promise<URLSearchParams>;
formData(): Promise<FormData>;
async init(): Promise<BodyInit | null>;
async json(): Promise<any>;
async text(): Promise<string>;
type(customMediaTypes?: Partial<Record<BodyType, string[]>>): BodyType;
[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;
}

§Constructors

§
new Body(serverRequest: Pick<ServerRequest, "request" | "headers" | "getBody">, reviver?: JsonReviver)
[src]

§Properties

§
has: boolean readonly
[src]

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 behavior. The only reliable way to determine if a request has a body or not is to attempt to read the body.

§
stream: ReadableStream<Uint8Array> | null readonly
[src]

Exposes the "raw" ReadableStream of the body.

§
used: boolean readonly
[src]

Returns true if the body has been consumed yet, otherwise false.

§Methods

§
arrayBuffer(): Promise<ArrayBuffer>
[src]

Reads a body to the end and resolves with the value as an {@link ArrayBuffer}

§
blob(): Promise<Blob>
[src]

Reads a body to the end and resolves with the value as a {@link Blob}.

§
form(): Promise<URLSearchParams>
[src]

Reads a body as a URL encoded form, resolving the value as {@link URLSearchParams}.

§
formData(): Promise<FormData>
[src]

Reads a body to the end attempting to parse the body as a set of {@link FormData}.

§
init(): Promise<BodyInit | null>
[src]

Return the body to be reused as BodyInit.

§
json(): Promise<any>
[src]

Reads a body to the end attempting to parse the body as a JSON value.

If a JSON reviver has been assigned, it will be used to parse the body.

§
text(): Promise<string>
[src]

Reads the body to the end resolving with a string.

§
type(customMediaTypes?: Partial<Record<BodyType, string[]>>): BodyType
[src]

Attempts to determine what type of the body is to help determine how best to attempt to decode the body. This performs analysis on the supplied Content-Type header of the request.

Note these are not authoritative and should only be used as guidance.

There is the ability to provide custom types when attempting to discern the type. Custom types are provided in the format of an object where the key is on of BodyType and the value is an array of media types to attempt to match. Values supplied will be additive to known media types.

The returned value is one of the following:

  • "binary" - The body appears to be binary data and should be consumed as an array buffer, readable stream or blob.
  • "form" - The value appears to be an URL encoded form and should be consumed as a form (URLSearchParams).
  • "form-data" - The value appears to be multipart form data and should be consumed as form data.
  • "json" - The value appears to be JSON data and should be consumed as decoded JSON.
  • "text" - The value appears to be text data and should be consumed as text.
  • "unknown" - Either there is no body or the body type could not be determined.
§
[Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string): string
[src]
§
[Symbol.for("nodejs.util.inspect.custom")](depth: number, options: any, inspect: (value: unknown, options?: unknown) => string): any
[src]