App
DELETE
(Fn [App, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(DELETE app pattern handler)
adds a DELETE route.
GET
(Fn [App, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(GET app pattern handler)
adds a GET route.
PATCH
(Fn [App, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(PATCH app pattern handler)
adds a PATCH route.
POST
(Fn [App, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(POST app pattern handler)
adds a POST route.
PUT
(Fn [App, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(PUT app pattern handler)
adds a PUT route.
WS
(Fn [App, String, (Fn [(Ref WSEvent a), (Ref (Map String String) b), (Ref WebSocket c)] ())] App)
(WS app pattern handler)
adds a WebSocket route. The handler is called for each lifecycle
event (WSEvent): Connect, Message, Binary, and Close.
(defn echo [event params ws]
(match-ref event
(WSEvent.Connect) (WebSocket.send ws @"connected")
(WSEvent.Message msg) (WebSocket.send ws (fmt "echo: %s" msg))
(WSEvent.Binary data) (WebSocket.send-binary ws data)
(WSEvent.Close) ()))
(defserver "0.0.0.0" 3000
(WS "/ws/echo" echo))
error-handler
(Fn [(Ref App a)] (Ref (Fn [(Ref Request b), Int, String] Response) a))
gets the error-handler property of a App.
init
(Fn [(Array Route), (Array WSRoute), (Fn [(Ref Request a), Int, String] Response)] App)
creates a App.
route
(Fn [App, String, String, (Fn [(Ref Request a), (Ref (Map String String) b)] Response)] App)
(route app method pattern handler)
adds a route to the app.
serve
(Fn [(Ref App a), (Ref (Array (Fn [(Ref Request b), (Ref (Map String String) c)] (Maybe Response) d)) a), (Ref (Array (Fn [(Ref Request e), (Ref (Map String String) f), Response] Response g)) a), (Ref String h), Int] ())
(serve app before-hooks after-hooks host port)
starts the web server on host:port.
Uses kqueue/epoll for concurrent connection handling with HTTP keep-alive. Sockets are non-blocking, reads accumulate into a per-connection buffer, and writes drain across writable events.
The loop is single-threaded, so peak throughput is bounded by one core. For multi-core scaling, run several copies behind a TCP load balancer.
set-error
(Fn [App, (Fn [(Ref Request a), Int, String] Response)] App)
(set-error app handler)
sets a custom error handler.
set-error-handler
(Fn [App, (Fn [(Ref Request a), Int, String] Response)] App)
sets the error-handler property of a App.
set-error-handler!
(Fn [(Ref App a), (Fn [(Ref Request b), Int, String] Response)] ())
sets the error-handler property of a App in place.
set-routes!
(Fn [(Ref App a), (Array Route)] ())
sets the routes property of a App in place.
set-ws-routes!
(Fn [(Ref App a), (Array WSRoute)] ())
sets the ws-routes property of a App in place.
static-dir
(Fn [App, String] App)
(static-dir app dir)
registers a wildcard GET route that serves files from
dir on disk via sendfile. Register after API routes so it acts as a
fallback.
update-error-handler
(Fn [App, (Ref (Fn [(Fn [(Ref Request a), Int, String] Response)] (Fn [(Ref Request a), Int, String] Response) b) c)] App)
updates the error-handler property of a App using a function f.
update-routes
(Fn [App, (Ref (Fn [(Array Route)] (Array Route) a) b)] App)
updates the routes property of a App using a function f.
update-ws-routes
(Fn [App, (Ref (Fn [(Array WSRoute)] (Array WSRoute) a) b)] App)
updates the ws-routes property of a App using a function f.
ws-ping-action
(Fn [Int, Int, Int, Int, Int, Bool] Int)
(ws-ping-action ping-interval max-missed idle pcount since-ping write-pending)
Decides what to do for a WebSocket connection's ping state. Returns 0 (nothing), 1 (send ping), or 2 (close as dead). Setting ping-interval to 0 or negative disables pinging.
ws-routes
(Fn [(Ref App a)] (Ref (Array WSRoute) a))
gets the ws-routes property of a App.