Modules · Connectivity · Network

Network

HTTP and WebSocket clients. Network lets your program reach the web reactively: a request such as Network.Web.Client.Get returns a Network.Web.Response held in a STATE LOCKED cell — pending until the reply arrives, then flowing through the rest of your program like any other value. It covers the full range of HTTP methods, form posts, header and cookie handling, URL encoding, and live WebSocket connections. Because every call is reactive, a response re-fetches whenever the URL or inputs it reads change.

Contents

Types

Functions

Types

Network.Web.Header

A single HTTP header as a name–value pair.

Fields

FieldTypeDescription
nameTextThe header field name.
valueTextThe header field value.

Definition

TYPE Network.Web.Header
  FIELD Text name
  FIELD Text value
A record pairing a header name with its value.

Example

LET Network.Web.Header accept = Network.Web.Header "Accept" "application/json"
A single request header.

Network.Web.Request

A prepared HTTP request: its URL, method, optional headers and body, and reactive reload state.

Fields

FieldTypeDescription
urlTextThe target URL.
methodTextThe HTTP method, such as GET or POST.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Headers to send, if any.
optionalBodyCollection.Optional(Text)The request body, if any.
reloadCountMaths.IntegerHow many times the request has reloaded.
isPollingLogic.MaybeYes when the request re-fetches on a timer.

Definition

TYPE Network.Web.Request
  FIELD Text url
  FIELD Text method
  FIELD Collection.Optional(Collection.Array(Network.Web.Header)) optionalHeaders
  FIELD Collection.Optional(Text) optionalBody
  FIELD Maths.Integer reloadCount
  FIELD Logic.Maybe isPolling
The fields the client fills in before a request is sent.

Example

LET Text target = request.url
Reads the target URL out of a request.

Network.Web.Response

The result of an HTTP request: its status code, headers, and body. It is pending until the reply arrives, so it is usually held in a STATE LOCKED cell.

Fields

FieldTypeDescription
statusCodeMaths.IntegerThe HTTP status code, such as 200 or 404.
headersCollection.Array(Network.Web.Header)The response headers.
responseBodyTextThe response body text.

Definition

TYPE Network.Web.Response
  FIELD Maths.Integer statusCode
  FIELD Collection.Array(Network.Web.Header) headers
  FIELD Text responseBody
A record holding everything returned by a request.

Example

STATE LOCKED Network.Web.Response response = Network.Web.Client.Get "https://api.example.com/data"
A response cell, locked until the request completes.

Network.Web.Url

A parsed URL broken into its protocol, domain, port, path, and optional query and anchor.

Fields

FieldTypeDescription
protocolTextThe scheme, such as https.
domainTextThe host name.
portMaths.IntegerThe port number.
pathTextThe path portion of the URL.
optionalQueryCollection.Optional(Collection.Map(Text))The query parameters, if any.
optionalAnchorCollection.Optional(Text)The fragment after #, if any.

Definition

TYPE Network.Web.Url
  FIELD Text protocol
  FIELD Text domain
  FIELD Maths.Integer port
  FIELD Text path
  FIELD Collection.Optional(Collection.Map(Text)) optionalQuery
  FIELD Collection.Optional(Text) optionalAnchor
A URL split into its parts.

Example

LET Text host = url.domain
Reads the domain out of a parsed URL.

Network.Websocket.Message

A single message sent or received over a WebSocket connection.

Fields

FieldTypeDescription
contentTextThe message text.

Definition

TYPE Network.Websocket.Message
  FIELD Text content
A record carrying one WebSocket message.

Example

LET Text text = message.content
Reads the text of a received message.

Functions

Network.Web.Client.Delete

Sends an HTTP DELETE request.

Parameters

NameTypeDescription
urlTextThe URL to delete.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, locked until the reply arrives.

Network.Web.Client.Get

Fetches a URL with an HTTP GET request.

Parameters

NameTypeDescription
urlTextThe URL to fetch.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, locked until the reply arrives.

Example

STATE LOCKED Network.Web.Response response = Network.Web.Client.Get "https://api.example.com/users"
A GET response, locked until the request completes.

Network.Web.Client.GetPolling

Repeatedly fetches a URL on a fixed interval.

Parameters

NameTypeDescription
urlTextThe URL to poll.
intervalMsMaths.IntegerMilliseconds between fetches.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the latest response, refreshed each interval.

Example

STATE LOCKED Network.Web.Response feed = Network.Web.Client.GetPolling "https://api.example.com/feed" 5000
Re-fetches every five seconds, updating the locked response.

Network.Web.Client.Head

Sends an HTTP HEAD request, retrieving only the headers.

Parameters

NameTypeDescription
urlTextThe URL to query.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, whose body is empty for a HEAD request.

Network.Web.Client.Options

Sends an HTTP OPTIONS request.

Parameters

NameTypeDescription
urlTextThe URL to query.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response describing the server's supported methods.

Network.Web.Client.Patch

Sends an HTTP PATCH request with an optional body.

Parameters

NameTypeDescription
urlTextThe URL to send to.
optionalBodyCollection.Optional(Text)The request body, if any.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, locked until the reply arrives.

Network.Web.Client.Post

Sends an HTTP POST request with an optional body.

Parameters

NameTypeDescription
urlTextThe URL to post to.
optionalBodyCollection.Optional(Text)The request body, if any.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, locked until the reply arrives.

Example

STATE LOCKED Network.Web.Response result = Network.Web.Client.Post "https://api.example.com/users" body
Posts body and holds the pending response.

Network.Web.Client.PostForm

Posts URL-encoded form fields as an HTTP POST.

Parameters

NameTypeDescription
urlTextThe URL to post to.
formFieldsCollection.Map(Text)The form field names and values.

Returns

Returns Network.Web.Response — the pending response; the fields are sent as application/x-www-form-urlencoded.

Example

STATE LOCKED Network.Web.Response result = Network.Web.Client.PostForm "https://example.com/login" fields
Submits fields as a URL-encoded form.

Network.Web.Client.Put

Sends an HTTP PUT request with an optional body.

Parameters

NameTypeDescription
urlTextThe URL to send to.
optionalBodyCollection.Optional(Text)The request body, if any.
optionalHeadersCollection.Optional(Collection.Array(Network.Web.Header))Extra request headers, if any.

Returns

Returns Network.Web.Response — the pending response, locked until the reply arrives.

Network.Web.Header.Emit

Emits one header into the enclosing GatherArray block.

Parameters

NameTypeDescription
nameTextThe header name.
valueTextThe header value.

Returns

Returns nothing — it adds one header to the surrounding Network.Web.Header.GatherArray.

Example

Network.Web.Header.Emit "Authorization" token
Adds an Authorization header inside a gather block.

Network.Web.Header.GatherArray

Collects the headers emitted in its block into an array.

Block

An indented block that calls Network.Web.Header.Emit once for each header to include.

Returns

Returns Collection.Array(Network.Web.Header) — every header emitted inside the block.

Example

LET Collection.Array(Network.Web.Header) headers = Network.Web.Header.GatherArray
Network.Web.Header.Emit "Content-Type" "application/json"
Network.Web.Header.Emit "Accept" "application/json"
Gathers the emitted headers into an array.

Network.Web.Header.ValuesByName

All values of headers matching a name, case-insensitively.

Parameters

NameTypeDescription
headersCollection.Array(Network.Web.Header)The headers to search.
headerNameTextThe header name to match.

Returns

Returns Collection.Array(Text) — every value whose header name matches, ignoring case.

Network.Web.Response.Zero

An empty response with status code zero and no body.

Returns

Returns Network.Web.Response — a blank response, useful as the initial value of a locked cell.

Example

LET Network.Web.Response empty = Network.Web.Response.Zero
A blank response before any request runs.

Network.Web.Url.EncodeString

Percent-encodes text for safe use in a URL.

Parameters

NameTypeDescription
unencodedStringTextThe text to encode.

Returns

Returns Text — the percent-encoded text.

Example

LET Text safe = Network.Web.Url.EncodeString query
Escapes query for use in a URL.

Network.Websocket.Client.Connection

Opens a live WebSocket connection over its scope.

Parameters

NameTypeDescription
receivedMessagesCollection.Array(Network.Websocket.Message)A state cell filled with incoming messages.
sendMessagesCollection.Array(Network.Websocket.Message)Messages to send over the connection.
addressTextThe WebSocket URL, such as wss://…

Returns

Returns nothing — it keeps the connection open while in scope, publishing incoming messages into receivedMessages.

Example

Network.Websocket.Client.Connection received outgoing "wss://chat.example.com"
Opens a connection, filling received with incoming messages.