Module

x/oak/body.ts>Body#type

A middleware framework for handling HTTP with Deno, Node, Bun and Cloudflare Workers 🐿️ 🦕
Very Popular
Go to Latest
method Body.prototype.type
import { Body } from "https://dotland.deno.dev/x/oak@14.2.0/body.ts";

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.

Parameters

optional
customMediaTypes: Partial<Record<BodyType, string[]>>