HTTP

HTTP Networking APIs

The HTTP interfaces are built to make it easier to use traditionally difficult protocol features. By never buffering complete requests or responses, users can stream data instead, making data transmission more efficient and flexible.

Classes

Server
ServerRequest
Body
IncomingResponse
ServerResponse

Members

(static, constant) METHODS :Array.<string>

A list of the HTTP methods that are supported by the parser.

Source:
Type:
  • Array.<string>

(static, constant) STATUS_CODES :Array.<string>

A collection of all the standard HTTP response status codes.

Source:
Type:
  • Array.<string>

Methods

(static) createServer(onRequestopt) → {Server}

Creates a new HTTP server.

Source:
Parameters:
Name Type Attributes Description
onRequest function <optional>

A function that is called whenever the server receives a HTTP request.

Returns:
Type:
Server

Representing the newly created HTTP server.

(static) request(url, optionsopt) → {Promise.<IncomingResponse>}

Performs an HTTP request.

Source:
Parameters:
Name Type Attributes Description
url string

The URL to which the HTTP request is sent.

options Object <optional>

Configuration options for the HTTP request.

Name Type Attributes Description
method string <optional>

The HTTP method to be used (e.g., GET, POST).

headers Object <optional>

An object containing request headers.

body string | Uint8Array | Readable <optional>

The body of the request.

timeout Number <optional>

A timeout in milliseconds for the request.

throwOnError boolean <optional>

Will throw an error for non-2xx response codes.

signal AbortSignal <optional>

An AbortSignal to cancel the request.

Returns:
Type:
Promise.<IncomingResponse>

Containing the HTTP response.

Type Definitions

Connection

An object representing an HTTP connection.

Properties:
Name Type Description
request ServerRequest

The incoming HTTP request.

response ServerResponse

The HTTP response that will be sent by the server.

Source:

SocketHost

Information about the host TCP socket.

Properties:
Name Type Description
port number

The port number on the local machine.

family string

The IP family of the local address (IPv4 or IPv6).

address string

The local IP address.

Source: