Skip to content

HttpMethod

Defines supported HTTP method names for the unstable HTTP modules.

Values are uppercase string literals such as "GET" and "POST", matching the method tokens used by HTTP requests and routes. This module also includes helpers for checking whether a method can carry a request body and whether an unknown value is one of the supported methods.

6 exports Added in v4.0.0 Source

Constants

all

Added in v4.0.0 Source

Provides a readonly set containing every supported HttpMethod literal.

When to use

Use when you need to iterate over or test membership against every supported HTTP method literal.

Signature

declare const all: ReadonlySet<HttpMethod>;

allShort

Added in v4.0.0 Source

Provides tuples mapping each supported HTTP method to its short request-constructor name.

When to use

Use when you need the mapping from supported HTTP method literals to their short request-constructor names.

Signature

declare const allShort: readonly [
  readonly ["GET", "get"],
  readonly ["POST", "post"],
  readonly ["PUT", "put"],
  readonly ["DELETE", "del"],
  readonly ["PATCH", "patch"],
  readonly ["HEAD", "head"],
  readonly ["OPTIONS", "options"],
  readonly ["TRACE", "trace"],
];

Guards

hasBody

Added in v4.0.0 Source

Returns true when a method can carry a request body and narrows it to HttpMethod.WithBody.

Signature

declare function hasBody(method: HttpMethod): method is WithBody;

isHttpMethod

Added in v4.0.0 Source

Checks whether a value is a HttpMethod.

Signature

declare function isHttpMethod(u: unknown): u is HttpMethod;

Models

HttpMethod type

Added in v4.0.0 Source

Union of supported uppercase HTTP method literals.

Signature

type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";

Other

HttpMethod

Added in v4.0.0 Source

Namespace containing subtype helpers associated with HttpMethod.