CX · Reference guidehttp
PlaygroundDownloadsAboutv0.18.0-pre.1

http

The HTTP/1.1 SERVER: an event-loop accept/respond surface over the cx-platform/net transport, with Server-Sent Events streaming for held-open push. Network operations are gated by the net capability — http adds no capability of its own. The client verbs and the pure message codec both halves share are cx-stdlib/http-client, a Ring-1 module of its own; a handler imports it beside this one to read a request or build a response.

http:serve

[$http:serve] -> element — Bind a listener and run an accept loop, calling a handler that maps each request to a response.

      [?lib 'cx-platform/http']
[?def h ($req::element) [response status=200]]
[$http:serve 'tcp://0.0.0.0:8080' $h]
    
      cx-err:CXER0271
    

http:listen

[$http:listen] -> element — Bind a listener for the low-level accept/respond path, returning an [http-server].

      [?lib 'cx-platform/http']
[$http:listen 'tcp://0.0.0.0:8080']
    
      cx-err:CXER0271
    

http:accept-iter

[$http:accept-iter] -> [iterator element] — Yield [exchange] handles for incoming requests as a single-use iterator.

      [?lib 'cx-platform/http']
[$http:accept-iter [http-server url='tcp://0.0.0.0:8080' state=listening]]
    
      cx-err:CXER0271
    

http:exchange-request

[$http:exchange-request] -> element — Return the parsed server-form [request] for an exchange.

      [?lib 'cx-platform/http']
[$http:exchange-request [exchange state=open url='tcp://0.0.0.0:8080']]
    
      cx-err:CXER0271
    

http:respond

[$http:respond] -> null — Write a response on an exchange's connection; interim 1xx may precede one final response.

      [?lib 'cx-platform/http']
[$http:respond [exchange state=open url='tcp://0.0.0.0:8080'] [response status=200]]
    
      cx-err:CXER0271
    

http:stop

[$http:stop] -> null — Gracefully drain a server, answering new exchanges with 503 until the grace period elapses.

      [?lib 'cx-platform/http']
[$http:stop [http-server url='tcp://0.0.0.0:8080' state=listening]]
    
      cx-err:CXER0271
    

http:sse

[$http:sse] -> element — Promote an open exchange to a held-open SSE stream, returning a [sse-stream] write handle.

      [?lib 'cx-platform/http']
[$http:sse [exchange state=open] {}]
    
      cx-err:CXER0271
    

http:send-event

[$http:send-event] -> null — Frame and flush one [event] as a chunk on an SSE stream.

      [?lib 'cx-platform/http']
[$http:send-event [sse-stream open=true] [event]]
    
      cx-err:CXER4539
    

http:sse-publish

[$http:sse-publish] -> int — Fan out one [event] to every connection subscribed to a topic (the concurrent-SSE producer half on the serve path); returns the delivered count. Subscribe by returning [sse-subscribe topic="…" [event …]?] from a serve handler.

      [?lib 'cx-platform/http']
[$http:sse-publish "prices" [event]]
    
      cx-err:CXER4539
    

http:heartbeat

[$http:heartbeat] -> null — Write one comment-only liveness frame to an SSE stream.

http:stream-open

[$http:stream-open] -> bool — Report whether an SSE write stream is still open — the producer-loop guard.

      [?lib 'cx-platform/http']
[$http:stream-open [sse-stream open=true]]
    
      true
    

http:ws-accept

[$http:ws-accept] -> element — Promote an open exchange to a WebSocket connection: validate the request through ws-handshake, write that 101 and hold the connection, answering a single-owner ws-conn. opts.request hands back a request the handler already read, since an exchange caches none.