CX · Reference guidehttp-client
PlaygroundDownloadsAboutv0.18.0-pre.1

http-client

HTTP/1.1 request/response semantics from the CLIENT side, plus the message codec both halves of HTTP share: method verbs, headers, materialized bodies, redirects, content decoding, connection pooling, and the Server-Sent Events read side. Built on the cx-platform/net transport; network operations are gated by the net capability — http-client adds no capability of its own, and message construction and introspection are pure. A non-2xx status is a value that flows, not a fault. The serving half is cx-platform/http.

http-client:client

[$http-client:client] -> element — Construct an [http-client] that pools connections under shared config — no network access yet.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:client]
    
      [http-client state=open on-close='http/close']
    

http-client:close

[$http-client:close] -> null — Close a client, server, or exchange handle, releasing its pooled sockets — idempotent.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:close [$http:client]]
    
      null
    

http-client:get

[$http-client:get] -> element — Issue a one-shot GET to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:get 'http://example.com/']
    
      cx-err:CXER0271
    

http-client:post

[$http-client:post] -> element — Issue a one-shot POST with a body to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:post 'http://example.com/' 'payload']
    
      cx-err:CXER0271
    

http-client:put

[$http-client:put] -> element — Issue a one-shot PUT with a body to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:put 'http://example.com/' 'payload']
    
      cx-err:CXER0271
    

http-client:del

[$http-client:del] -> element — Issue a one-shot DELETE to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:del 'http://example.com/']
    
      cx-err:CXER0271
    

http-client:patch

[$http-client:patch] -> element — Issue a one-shot PATCH with a body to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:patch 'http://example.com/' 'payload']
    
      cx-err:CXER0271
    

http-client:head

[$http-client:head] -> element — Issue a one-shot HEAD to a URL and return the bodyless [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:head 'http://example.com/']
    
      cx-err:CXER0271
    

http-client:options

[$http-client:options] -> element — Issue a one-shot OPTIONS to a URL and return the [response].

      [?lib 'cx-stdlib/http-client' as=http]
[$http:options 'http://example.com/']
    
      cx-err:CXER0271
    

http-client:request

[$http-client:request] -> element — Issue a one-shot request with an arbitrary method (including custom methods with bodies).

      [?lib 'cx-stdlib/http-client' as=http]
[$http:request 'PURGE' 'http://example.com/']
    
      cx-err:CXER0271
    

http-client:send

[$http-client:send] -> element — Issue a built [request] through a pooled client and return its [response] — concurrency-safe.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:send [$http:client] [request method="GET" url="http://h/"]]
    
      cx-err:CXER0271
    

http-client:status

[$http-client:status] -> int — Return the HTTP status code of a response.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:status [response status=200]]
    
      200
    

http-client:ok

[$http-client:ok] -> bool — Report whether a response status is in the 200–299 success range.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:ok [response status=200]]
    
      true
    

http-client:header

[$http-client:header] -> element — Return the first header matching a name (case-insensitive), or absence if none.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:header [response status=200 [headers [header name="Content-Type" value="application/json"]]] 'content-type']
    
      [header name=Content-Type value='application/json']
    

http-client:headers

[$http-client:headers] -> [sequence element] — Return all headers in receive order, duplicates preserved.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:headers [response status=200 [headers [header name="A" value="1"] [header name="B" value="c"]]]]
    
      ([header name=A value='1'], [header name=B value=c])
    

http-client:headers-named

[$http-client:headers-named] -> [sequence element] — Return all headers matching a name (case-insensitive) in receive order.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:headers-named [response status=200 [headers [header name="Set-Cookie" value="a"] [header name="Set-Cookie" value="b"]]] 'set-cookie']
    
      ([header name=Set-Cookie value=a], [header name=Set-Cookie value=b])
    

http-client:has-body

[$http-client:has-body] -> bool — Report whether a message structurally frames a body, distinguishing absent from empty.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:has-body [response status=200 [body 'hi']]]
    
      true
    

http-client:body-bytes

[$http-client:body-bytes] -> bytes — Return the message body octets, decoded if auto-decompress applied — total, empty if no body.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:body-bytes [response status=200 [body 'hi']]]
    
      0x6869::bytes
    

http-client:body-bytes-wire

[$http-client:body-bytes-wire] -> bytes — Return the original on-the-wire body octets before any decompression.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:body-bytes-wire [response status=200 [body 'gz']]]
    
      0x677a::bytes
    

http-client:body-text

[$http-client:body-text] -> string — Decode the body to text using the Content-Type charset (default UTF-8).

      [?lib 'cx-stdlib/http-client' as=http]
[$http:body-text [response status=200 [body 'hello']]]
    
      hello
    

http-client:sse-connect

[$http-client:sse-connect] -> element — Open a streaming GET and return an [sse-source] read handle on a 2xx event stream.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:sse-connect "http://idp.test/stream" {}]
    
      cx-err:CXER0271
    

http-client:sse-events

[$http-client:sse-events] -> [iterator element] — Yield parsed [event]s from a source in arrival order as a single-use iterator.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:sse-events [sse-source open=true]]
    
      cx-err:CXER0271
    

http-client:source-open

[$http-client:source-open] -> bool — Report whether an SSE read source is still open.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:source-open [sse-source open=false]]
    
      false
    

http-client:last-event-id

[$http-client:last-event-id] -> element — Return the last received event id from a source, or absence if none.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:last-event-id [sse-source last-event-id="42"]]
    
      '42'
    

http-client:sse-state

[$http-client:sse-state] -> element — Read a source's live state off its connection: [sse-state open=<bool> heartbeats=<n> last-event-id=<id>] -- whether the stream is still open, how many heartbeat (comment-only) frames it has consumed since connect, and the id of the last event delivered (absent when none). It tells the ends of a drained [?receive] apart: a clean close, a heartbeat-only window and a silent one.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:sse-state [sse-source open=true]]
    
      [sse-state open=false heartbeats=0]
    

http-client:ws-connect

[$http-client:ws-connect] -> element — Dial ws:// or wss:// over net's existing TCP/TLS surface, mint the key, issue the upgrade GET and hand the answer to ws-confirm; a 3xx is refused and never followed, and on any failure the socket is closed rather than leaked.

http-client:ws-handshake

[$http-client:ws-handshake] -> element — The SERVER's decision over a received request: the 101 it would write with the derived Sec-WebSocket-Accept, or the refusal whose http code the 400 or 426 is built from.

http-client:ws-confirm

[$http-client:ws-confirm] -> element — The CLIENT's decision over the key it sent and the response it got: the negotiated subprotocol, the absence channel when none was selected, a response VALUE for a non-101 that is not a redirect, or a refusal.

http-client:ws-send

[$http-client:ws-send] -> null — Fragment a message at the connection's frame bound, mask each frame when this end is the client, and write them in order; a text payload that is not valid UTF-8 refuses before a single octet is written.

http-client:ws-messages

[$http-client:ws-messages] -> [iterator element] — The live single-use iterator of assembled messages in arrival order; Ping and Pong are consumed and answered automatically and a Close ends the walk, so clean end-of-stream is absence.

http-client:ws-ping

[$http-client:ws-ping] -> null — Write one Ping carrying at most 125 octets of application data, which is what makes a heartbeat measurable rather than merely present.

http-client:ws-close

[$http-client:ws-close] -> null — Write the Close and drain; idempotent, which is what makes it safe as the exit of a with-open scope.

http-client:ws-open

[$http-client:ws-open] -> bool — Whether the connection handle is still open — a pure accessor that opens nothing and reads no socket.

http-client:ws-subprotocol

[$http-client:ws-subprotocol] -> element — The subprotocol this connection negotiated, or the absence channel when the server selected none.

http-client:ws-state

[$http-client:ws-state] -> element — Read a connection's live state: [ws-state open=<bool> close=<code> heartbeats=<n>] -- whether it is open, the peer's Close code (absent before a Close), and how many pings and pongs it has consumed since connect. It tells the ends of a drained [?receive] apart.

      [?lib 'cx-stdlib/http-client' as=http]
[$http:ws-state [ws-conn open=true]]
    
      [ws-state open=false heartbeats=0]