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 HttpHeadersType 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 HttpOptionsType 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?: stringPEM text or a PEM file for an additional private certificate authority.
Other members of HttpOptions
ts
headers?: HttpHeaders
body?: string
json?: Object
timeout?: floatHttpRequestOptions class
ts
class HttpRequestOptions extends HttpOptionsType only: the runtime hands you instances; you never construct it yourself.
Options for Http.request, including the required request URL.
ts
url: string
method?: stringHttpResponse class
ts
class HttpResponseType 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(): stringReads the response body as a string.
Returns: The decoded response body.
HttpResponse.json
ts
json(): ObjectParses the response body as JSON.
Returns: A parsed JSON object, or undefined if parsing fails.
HttpResponse.bytes
ts
bytes(): BufferReads the response body as bytes.
Returns: The response body as a Buffer.
HttpResponse.text
ts
static text(content: string, status?: int, headers?: HttpHeaders): HttpResponseConstructs 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): HttpResponseConstructs 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): HttpResponseConstructs 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): HttpResponseConstructs 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: stringHttpServerRequest class
ts
class HttpServerRequestType only: the runtime hands you instances; you never construct it yourself.
A bounded, lazily decoded inbound server request.
HttpServerRequest.params
ts
readonly params: HttpParamsPercent-decoded values captured from :param route segments.
HttpServerRequest.text
ts
text(): stringReads the request body as a string.
Returns: The decoded request body.
HttpServerRequest.json
ts
json(): ObjectParses the request body as JSON.
Returns: A parsed JSON object, or undefined if parsing fails.
HttpServerRequest.bytes
ts
bytes(): BufferReads 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: HttpHeadersHttpParams class
ts
class HttpParamsType 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 HttpServerType only: the runtime hands you instances; you never construct it yourself.
HttpServer.get
ts
get(path: string, handler: (request: HttpServerRequest) => HttpResponse | Promise<HttpResponse>): voidRegisters 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>): voidRegisters 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>): voidRegisters 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>): voidRegisters 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): voidMounts 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): voidRegisters 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: intHttpServeOptions class
ts
class HttpServeOptionsType only: the runtime hands you instances; you never construct it yourself.
HTTP server limits and timeouts. Timeout values are seconds.
HttpServeOptions.maxBodySize
ts
maxBodySize?: intCompatibility 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 HttpMethodHTTP 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: stringHttpStatus static class
ts
static class HttpStatusNamed 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: intHttp static class
ts
static class HttpHttp.DEFAULT_MAX_REQUEST_LINE_BYTES
ts
static readonly DEFAULT_MAX_REQUEST_LINE_BYTES: intDefault maximum HTTP request line size in bytes.
Http.DEFAULT_MAX_HEADER_COUNT
ts
static readonly DEFAULT_MAX_HEADER_COUNT: intDefault maximum number of HTTP headers per request.
Http.DEFAULT_MAX_HEADER_BYTES
ts
static readonly DEFAULT_MAX_HEADER_BYTES: intDefault maximum total header size in bytes.
Http.DEFAULT_MAX_BODY_BYTES
ts
static readonly DEFAULT_MAX_BODY_BYTES: intDefault maximum request body size in bytes.
Http.DEFAULT_HEADER_TIMEOUT
ts
static readonly DEFAULT_HEADER_TIMEOUT: floatDefault header read timeout in seconds.
Http.DEFAULT_BODY_TIMEOUT
ts
static readonly DEFAULT_BODY_TIMEOUT: floatDefault body read timeout in seconds.
Http.DEFAULT_IDLE_TIMEOUT
ts
static readonly DEFAULT_IDLE_TIMEOUT: floatDefault idle connection timeout in seconds.
Http.DEFAULT_WRITE_TIMEOUT
ts
static readonly DEFAULT_WRITE_TIMEOUT: floatDefault write timeout in seconds.
Http.DEFAULT_GRACEFUL_CLOSE_TIMEOUT
ts
static readonly DEFAULT_GRACEFUL_CLOSE_TIMEOUT: floatDefault graceful close timeout in seconds.
Http.DEFAULT_MAX_CONNECTIONS
ts
static readonly DEFAULT_MAX_CONNECTIONS: intDefault maximum number of concurrent connections.
Http.DEFAULT_MAX_PENDING_WRITE_BYTES
ts
static readonly DEFAULT_MAX_PENDING_WRITE_BYTES: intDefault maximum pending write buffer size in bytes.
Http.DEFAULT_MAX_STATIC_FILE_BYTES
ts
static readonly DEFAULT_MAX_STATIC_FILE_BYTES: intDefault maximum static file size in bytes.
Http.DELETE
ts
static readonly DELETE: stringThe HTTP DELETE method.
Http.GET
ts
static readonly GET: stringThe HTTP GET method.
Http.HEAD
ts
static readonly HEAD: stringThe HTTP HEAD method.
Http.OPTIONS
ts
static readonly OPTIONS: stringThe HTTP OPTIONS method.
Http.PATCH
ts
static readonly PATCH: stringThe HTTP PATCH method.
Http.POST
ts
static readonly POST: stringThe HTTP POST method.
Http.PUT
ts
static readonly PUT: stringThe 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.