Namespace: joker.http
v1.0Contents
Summary
Provides HTTP client and server implementations.
Index
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
send
Function v1.0(send request)Sends an HTTP request and returns an HTTP response.
request is a map with the following keys:
- url (string)
- method (string, keyword or symbol, defaults to :get)
- body (string)
- host (string, overrides Host header if provided)
- headers (map).
All keys except for url are optional.
response is a map with the following keys:
- status (int)
- body (string)
- headers (map)
- content-length (int) -
start-file-server
Function v1.0(start-file-server addr root)Starts HTTP server on the TCP network address addr that
serves HTTP requests with the contents of the file system rooted at root. -
start-server
Function v1.0(start-server addr handler)Starts HTTP server on the TCP network address addr.
handler receives a request map and returns a response map.
A response map with an :sse channel streams Server-Sent Events
until the channel closes or the client disconnects. Values read from
the channel may be strings, which are sent as data events, or maps with
any of the following keys:
- data (string)
- event (string)
- id (string)
- retry (int)
- comment (string)
Optional status and headers keys are applied before streaming. If the
response contains an on-close fn, it is called with a map after
streaming ends. The map contains a reason key with one of
:channel-closed, :client-closed, :write-error or :error. For
:write-error and :error, the map also contains an error key with an
Error object. SSE responses default to Content-Type text/event-stream,
Cache-Control no-cache and Connection keep-alive unless those headers
are provided.