Skip to content

http ​

Asynchronous HTTP client and an HTTP server.

Import

ts
import { HttpMethod, HttpStatus, Http } from "http";

Needs the "net" permission in thicket.json.

HttpHeaders class ​

ts
class HttpHeaders

Type only: the runtime hands you instances; you never construct it yourself.

HTTP response headers keyed by their field name.

HttpHeaders.get ​

ts
get(name: string): string?

Retrieves a header value by name; header names are case-insensitive.

Parameters

  • name: The header field name.

Returns: The header value, or null if not found.

HttpOptions class ​

ts
class HttpOptions

Type only: the runtime hands you instances; you never construct it yourself.

Options shared by Http's convenience methods. timeout is in seconds.

HttpOptions.ca ​

ts
ca?: string

PEM text or a PEM file for an additional private certificate authority.

Other members of HttpOptions ​

ts
headers?: HttpHeaders
body?: string
json?: Object
timeout?: float

HttpRequestOptions class ​

ts
class HttpRequestOptions extends HttpOptions

Type only: the runtime hands you instances; you never construct it yourself.

Options for Http.request, including the required request URL.

ts
url: string
method?: string

HttpResponse class ​

ts
class HttpResponse

Type only: the runtime hands you instances; you never construct it yourself.

A completed HTTP response. Transport and timeout failures reject instead.

HttpResponse.text ​

ts
text(): string

Reads the response body as a string.

Returns: The decoded response body.

HttpResponse.json ​

ts
json(): Object

Parses the response body as JSON.

Returns: A parsed JSON object, or undefined if parsing fails.

HttpResponse.bytes ​

ts
bytes(): Buffer

Reads the response body as bytes.

Returns: The response body as a Buffer.

HttpResponse.text ​

ts
static text(content: string, status?: int, headers?: HttpHeaders): HttpResponse

Constructs an HttpResponse with a string body.

Parameters

  • content: The response body text.
  • status: HTTP status code; default 200.
  • headers: Optional HttpHeaders object.

Returns: An HttpResponse.

HttpResponse.json ​

ts
static json(content: Object, status?: int, headers?: HttpHeaders): HttpResponse

Constructs an HttpResponse with a JSON body.

Parameters

  • content: The object to serialize as JSON.
  • status: HTTP status code; default 200.
  • headers: Optional HttpHeaders object.

Returns: An HttpResponse.

HttpResponse.bytes ​

ts
static bytes(content: Buffer, status?: int, headers?: HttpHeaders): HttpResponse

Constructs an HttpResponse with a binary body.

Parameters

  • content: The response body bytes.
  • status: HTTP status code; default 200.
  • headers: Optional HttpHeaders object.

Returns: An HttpResponse.

HttpResponse.redirect ​

ts
static redirect(location: string, status?: int): HttpResponse

Constructs a redirect response.

Parameters

  • location: The Location header value.
  • status: HTTP status code; default 302.

Returns: An HttpResponse.

Other members of HttpResponse ​

ts
readonly status: int
readonly ok: boolean
readonly headers: HttpHeaders
readonly body: string

HttpServerRequest class ​

ts
class HttpServerRequest

Type only: the runtime hands you instances; you never construct it yourself.

A bounded, lazily decoded inbound server request.

HttpServerRequest.params ​

ts
readonly params: HttpParams

Percent-decoded values captured from :param route segments.

HttpServerRequest.text ​

ts
text(): string

Reads the request body as a string.

Returns: The decoded request body.

HttpServerRequest.json ​

ts
json(): Object

Parses the request body as JSON.

Returns: A parsed JSON object, or undefined if parsing fails.

HttpServerRequest.bytes ​

ts
bytes(): Buffer

Reads the request body as bytes.

Returns: The request body as a Buffer.

Other members of HttpServerRequest ​

ts
readonly method: string
readonly path: string
readonly query: string
readonly headers: HttpHeaders

HttpParams class ​

ts
class HttpParams

Type only: the runtime hands you instances; you never construct it yourself.

HttpParams.get ​

ts
get(name: string): string?

Retrieves a route parameter value by name.

Parameters

  • name: The parameter name from a :param route segment.

Returns: The percent-decoded parameter value, or null if not found.

HttpServer class ​

ts
class HttpServer

Type only: the runtime hands you instances; you never construct it yourself.

HttpServer.get ​

ts
get(path: string, handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>): void

Registers a handler for GET requests at the given path.

Parameters

  • path: The URL path pattern, with :name for captured parameters.
  • handler: A function that receives the request and returns a response or Promise.

HttpServer.post ​

ts
post(path: string, handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>): void

Registers a handler for POST requests at the given path.

Parameters

  • path: The URL path pattern, with :name for captured parameters.
  • handler: A function that receives the request and returns a response or Promise.

HttpServer.put ​

ts
put(path: string, handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>): void

Registers a handler for PUT requests at the given path.

Parameters

  • path: The URL path pattern, with :name for captured parameters.
  • handler: A function that receives the request and returns a response or Promise.

HttpServer.delete ​

ts
delete(path: string, handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>): void

Registers a handler for DELETE requests at the given path.

Parameters

  • path: The URL path pattern, with :name for captured parameters.
  • handler: A function that receives the request and returns a response or Promise.

HttpServer.serveStatic ​

ts
serveStatic(urlPrefix: string, folder: string, index?: string): void
serveStatic(urlPrefix: string, assets: Object, index?: string): void

Mounts static files from a folder at the given URL prefix.

Parameters

  • urlPrefix: The URL path prefix; e.g., "/static".
  • folder: The filesystem folder path to serve.
  • index: Optional index file name for directory requests; default none.

HttpServer.onUpgrade ​

ts
onUpgrade(handler: (request: HttpServerRequest, socket: WebSocket) => void): void
onUpgrade(path: string, handler: (request: HttpServerRequest, socket: WebSocket) => void): void

Registers a default WebSocket upgrade handler for all paths.

Parameters

  • handler: A function that receives the request and WebSocket.

HttpServer.close ​

ts
close(): Promise<void>

Gracefully closes the server.

Returns: A Promise that resolves when the server is closed.

Other members of HttpServer ​

ts
readonly port: int
readonly connectionCount: int

HttpServeOptions class ​

ts
class HttpServeOptions

Type only: the runtime hands you instances; you never construct it yourself.

HTTP server limits and timeouts. Timeout values are seconds.

HttpServeOptions.maxBodySize ​

ts
maxBodySize?: int

Compatibility spelling retained from the original server proposal.

Other members of HttpServeOptions ​

ts
port: int
handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>
host?: string
maxRequestLineBytes?: int
maxHeaderCount?: int
maxHeaderBytes?: int
maxBodyBytes?: int
headerTimeout?: float
bodyTimeout?: float
idleTimeout?: float
writeTimeout?: float
gracefulCloseTimeout?: float
maxConnections?: int
maxPendingWriteBytes?: int
maxStaticFileBytes?: int
maxPayload?: int
verifyOrigin?: Array<string> | ((origin: string, request: HttpServerRequest) => boolean)

HttpMethod static class ​

ts
static class HttpMethod

HTTP method name constants for request routing.

ts
static readonly DELETE: string
static readonly GET: string
static readonly HEAD: string
static readonly OPTIONS: string
static readonly PATCH: string
static readonly POST: string
static readonly PUT: string

HttpStatus static class ​

ts
static class HttpStatus

Named status-code constants for HTTP response comparisons.

ts
static readonly CONTINUE: int
static readonly OK: int
static readonly CREATED: int
static readonly NO_CONTENT: int
static readonly MOVED_PERMANENTLY: int
static readonly FOUND: int
static readonly NOT_MODIFIED: int
static readonly BAD_REQUEST: int
static readonly UNAUTHORIZED: int
static readonly FORBIDDEN: int
static readonly NOT_FOUND: int
static readonly REQUEST_TIMEOUT: int
static readonly PAYLOAD_TOO_LARGE: int
static readonly TOO_MANY_REQUESTS: int
static readonly REQUEST_HEADER_FIELDS_TOO_LARGE: int
static readonly UPGRADE_REQUIRED: int
static readonly INTERNAL_SERVER_ERROR: int
static readonly BAD_GATEWAY: int
static readonly SERVICE_UNAVAILABLE: int

Http static class ​

ts
static class Http

Http.DEFAULT_MAX_REQUEST_LINE_BYTES ​

ts
static readonly DEFAULT_MAX_REQUEST_LINE_BYTES: int

Default maximum HTTP request line size in bytes.

Http.DEFAULT_MAX_HEADER_COUNT ​

ts
static readonly DEFAULT_MAX_HEADER_COUNT: int

Default maximum number of HTTP headers per request.

Http.DEFAULT_MAX_HEADER_BYTES ​

ts
static readonly DEFAULT_MAX_HEADER_BYTES: int

Default maximum total header size in bytes.

Http.DEFAULT_MAX_BODY_BYTES ​

ts
static readonly DEFAULT_MAX_BODY_BYTES: int

Default maximum request body size in bytes.

Http.DEFAULT_HEADER_TIMEOUT ​

ts
static readonly DEFAULT_HEADER_TIMEOUT: float

Default header read timeout in seconds.

Http.DEFAULT_BODY_TIMEOUT ​

ts
static readonly DEFAULT_BODY_TIMEOUT: float

Default body read timeout in seconds.

Http.DEFAULT_IDLE_TIMEOUT ​

ts
static readonly DEFAULT_IDLE_TIMEOUT: float

Default idle connection timeout in seconds.

Http.DEFAULT_WRITE_TIMEOUT ​

ts
static readonly DEFAULT_WRITE_TIMEOUT: float

Default write timeout in seconds.

Http.DEFAULT_GRACEFUL_CLOSE_TIMEOUT ​

ts
static readonly DEFAULT_GRACEFUL_CLOSE_TIMEOUT: float

Default graceful close timeout in seconds.

Http.DEFAULT_MAX_CONNECTIONS ​

ts
static readonly DEFAULT_MAX_CONNECTIONS: int

Default maximum number of concurrent connections.

Http.DEFAULT_MAX_PENDING_WRITE_BYTES ​

ts
static readonly DEFAULT_MAX_PENDING_WRITE_BYTES: int

Default maximum pending write buffer size in bytes.

Http.DEFAULT_MAX_STATIC_FILE_BYTES ​

ts
static readonly DEFAULT_MAX_STATIC_FILE_BYTES: int

Default maximum static file size in bytes.

Http.DELETE ​

ts
static readonly DELETE: string

The HTTP DELETE method.

Http.GET ​

ts
static readonly GET: string

The HTTP GET method.

Http.HEAD ​

ts
static readonly HEAD: string

The HTTP HEAD method.

Http.OPTIONS ​

ts
static readonly OPTIONS: string

The HTTP OPTIONS method.

Http.PATCH ​

ts
static readonly PATCH: string

The HTTP PATCH method.

Http.POST ​

ts
static readonly POST: string

The HTTP POST method.

Http.PUT ​

ts
static readonly PUT: string

The HTTP PUT method.

Http.delete ​

ts
static delete(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP DELETE request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.get ​

ts
static get(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP GET request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.head ​

ts
static head(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP HEAD request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.options ​

ts
static options(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP OPTIONS request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.patch ​

ts
static patch(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP PATCH request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.post ​

ts
static post(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP POST request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.put ​

ts
static put(url: string, opts?: HttpOptions): Promise<HttpResponse>

Sends an HTTP PUT request.

Parameters

  • url: The request URL.
  • opts: Optional request options (headers, timeout, etc.).

Returns: A Promise resolving to the HttpResponse.

Http.request ​

ts
static request(opts: HttpRequestOptions): Promise<HttpResponse>

Sends a custom HTTP request.

Parameters

  • opts: Request options, including url and optional method.

Returns: A Promise resolving to the HttpResponse.

Http.serve ​

ts
static serve(options: HttpServeOptions): Promise<HttpServer>

Starts an HTTP server.

Parameters

  • options: Server options including port, handler, and limits.

Returns: A Promise resolving to the HttpServer.


Generated from lang/types/http.d.tks in the ThicketScript repository.