Net.HTTP
module Net.HTTP
Buffered HTTP clients, responses, and a small declaration-ordered server router. Requests never follow redirects or perform generic retries implicitly.
using Net.HTTP
let response = HTTP.get("https://example.test/").try
response.status.success? # => true
For connection reuse and statistics, own a client explicitly:
let client = Client.open.try
let response = client.get("https://example.test/").try
client.close.try
record Headers
An insertion-ordered HTTP field collection. Names compare case-insensitively and duplicate fields are preserved.
Fields
Implements Showable, Inspectable.
Methods
add
add(name: String, value: String) -> Headers
Appends a field without replacing existing fields of the same name.
Examples
+Headers.empty.add("Accept", "text/plain")+
set
set(name: String, value: String) -> Headers
Replaces all fields of name with one value.
Examples
+headers.set("Content-Type", "application/json")+
showValue Showable
showValue : String
Renders fields while replacing authorization and cookie values with ***.
inspectValue Inspectable
inspectValue(colors: Bool) -> String
Structural inspection uses the same credential-safe rendering.
From Showable
record Status
A validated HTTP status code in 100..599.
Fields
codeInteger
Methods
record Response<B>
A typed HTTP response envelope whose body representation is explicit.
Fields
record Request<B>
A typed HTTP request envelope whose body representation is explicit.
Fields
record RouteContext
Route captures decoded after path segmentation.
Fields
Methods
record Context
Per-request server context.
Fields
routeRouteContext
type Handler
A buffered HTTP route handler.
record Route
One declared route; routers preserve declaration order.
Fields
record Router
An immutable, declaration-ordered HTTP router.
Fields
routes[Route]optional
Methods
route
route(method: String, path: String, handler: Handler) -> Router
Appends a route; earlier matching declarations win.
get
get(path: String, handler: Handler) -> Router
Appends a GET route. GET also supplies automatic HEAD fallback.
head
head(path: String, handler: Handler) -> Router
Appends an explicit HEAD route, overriding automatic GET fallback.
record ShutdownReport
Counts and elapsed time from graceful server shutdown.
Fields
record ServerOptions
Bounded HTTP server resources and default graceful-shutdown duration.
Fields
record PoolOptions
HTTP connection-pool bounds and idle lifetime.
Fields
record ClientOptions
Options owned by an explicit HTTP client.
Fields
poolPoolOptionsoptional
record ClientStatistics
Lifetime request/reuse counters plus current pooled connections.
Fields
record ClientCloseReport
Resources released by Client.close.
Fields
closedConnectionsInteger
type Client
The pooled HTTP client. An opaque handle over the connection pool that owns it; Client.open makes one and client.close releases it.
Methods
request
request(method: String, url: String, headers: Headers, body: Binary) -> Result<Response<Binary>, NetError>
Sends a buffered request. Redirects and generic retries are not implicit.
post
post(url: String, body: Binary) -> Result<Response<Binary>, NetError>
Sends a buffered binary POST request.
put
put(url: String, body: Binary) -> Result<Response<Binary>, NetError>
Sends a buffered binary PUT request.
patch
patch(url: String, body: Binary) -> Result<Response<Binary>, NetError>
Sends a buffered binary PATCH request.
delete
delete(url: String) -> Result<Response<Binary>, NetError>
Sends a DELETE request with an empty body.
head
head(url: String) -> Result<Response<Binary>, NetError>
Sends a HEAD request; the returned body is empty.
close
close : Result<ClientCloseReport, NetError>
Idempotently closes the client and every idle pooled connection.
module Net.HTTP.Headers
module Net.HTTP.Status
module Net.HTTP.Response
binary
binary(status: Integer, body: Binary, headers: Headers) -> Response<Binary>
Builds a buffered binary response with validated headers.
Examples
+Response.binary(200, Binary.empty, Headers.empty)+
module Net.HTTP.Router
build constant
Examples
+Router.build.get("/health", { |request, context| Response.text(200, "ok") })+
module Net.HTTP.Server
start
start(endpoint: Net.Socket.TCP.Endpoint, router: Router, options: ServerOptions) -> Result<Running, NetError>
Starts a server with conservative defaults and returns immediately.
Examples
let router = Router.build.get("/health", do |request, context|
Response.text(200, "ok")
end)
let endpoint = Net.Socket.TCP.Endpoint.loopback(Net.Port.from(0).try)
let server = Server.start(endpoint, router).try
Server.stop(server).try
serve
serve(endpoint: Net.Socket.TCP.Endpoint, router: Router, options: ServerOptions) -> Result<Void, NetError>
Starts with defaults and blocks until the server stops.
stop
stop(server: Running, grace: Duration) -> Result<ShutdownReport, NetError>
Gracefully stops using the duration captured at start.
localAddress
localAddress(server: Running) -> Net.Socket.TCP.Endpoint
Returns the bound address, including ephemeral port
type Running
An opaque asynchronous HTTP server handle.
module Net.HTTP.Client
module Net.HTTP.HTTP
request
request : String -> String -> Headers -> Binary -> Result<Response<Binary>, NetError>
Sends one stateless buffered request with no redirect or hidden retry.
Examples
+HTTP.request("GET", "https://example.test/").try+
get
get(url: String) -> Result<Response<Binary>, NetError>
Sends one stateless buffered GET.
Examples
+HTTP.get("https://example.test/").try+
delete
delete(url: String) -> Result<Response<Binary>, NetError>
Sends one stateless DELETE with an empty body.
head
head(url: String) -> Result<Response<Binary>, NetError>
Sends one stateless HEAD and returns an empty response body.
options
options(url: String) -> Result<Response<Binary>, NetError>
Sends one stateless OPTIONS request.
post
post(url: String, body: Binary) -> Result<Response<Binary>, NetError>
Sends one stateless buffered binary POST.
Submodules
Net.HTTP.WebSocketHigh-level RFC 6455 client messages. The runtime handles fragmentation and ping/pong frames; reconnect and heartbeat policies remain application-owned.