noir-async.core documentation

The main namespace to require when building an app with noir-async.

async-push

(async-push conn data)
This should be the only method you need to send data.
All pushes to the client through this are asynchronous.
If it's a websocket this sends a message.
If it's a normal connection, it sends the entire response in one shot and closes the connection.
To start a multi-part connection, send a header with the the option :chunked set to true
  ex: (async-push conn {:chunked true})
If this is a multipart connection (a chunked header has been sent been called earlier) this sends a new body chunk.

chunked?

(chunked? conn)
Is this connection in chunked mode?

close-connection

(close-connection conn)
Closes the connection. No more data can be sent / received after this

closed?

(closed? conn)
Returns true if the connection is already closed

defpage-async

(defpage-async route request-bindings conn-binding & body)
Creates an asynchronous noir route. This route can handle both
regular HTTP and Websocket connections. For regular HTTP
responses can be delivered in one shot, or in chunked mode.

on-close

(on-close {:keys [request-channel response-channel]} handler)
Sets a callback to handle a closed connection. Callback takes no arguments.

on-receive

(on-receive {:keys [request-channel]} handler)
Sets a callback to handle websocket messages.
Callback takes one argument, a string containing the message.

one-shot?

(one-shot? conn)
true if the connection is able to send a oneshot response, I.E. not chunked or a websocket.

readable-channel

(readable-channel {:keys [request-channel]})
Returns the connection's readable channel. Useful if you need to directly pipe using lamina.

regular?

(regular? conn)
true if this is a regular HTTP connection, I.E. not a websocket.

request-body-byte-buffer

(request-body-byte-buffer conn)
Retrieves the request body as a ByteBuffer

request-body-str

(request-body-str conn)
Retrieves the request body as a string.

websocket?

(websocket? conn)
True if the connection was is a websocket

writable-channel

(writable-channel {:keys [request-channel response-channel], :as conn})
Returns the connection's writable channel. Useful if you need to directly pipe using lamina.