/web/app
Core full-stack web application primitives: cookies, flash messages, query/form params, responses, and trie router.
Constants#
*request*#
constant · AnyDynamic variable bound to the active HTTP request inside request handlers.
noneFunctions & symbols#
add-classes#
Mutates `attrs:class` in place by appending `classes` without overwriting existing classes.
| Parameter | Type | Optional | Description |
|---|---|---|---|
attrs | Map | required | Mutable attributes Map |
classes | Any | required | One or more class names/arrays/maps |
Any(repr-html/add-classes attrs "card" "elevated")build-query-string#
Serializes a dictionary of query parameters into a URL query string component. Automatically sorts keys alphabetically for predictable and deterministic URLs.
| Parameter | Type | Optional | Description |
|---|---|---|---|
query-map | Any | required | — |
Anyclear-named-routes#
Clears all registered routes in the package default registry (useful for testing).
Anyclient-ip-of#
Resolves the client IP address from X-Forwarded-For, X-Real-IP, or remote-addr.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyclose-websocket#
Cleanly closes a server WebSocket connection with an optional close status code and reason.
| Parameter | Type | Optional | Description |
|---|---|---|---|
channel | WS-Channel | required | Connected server WebSocket channel |
options | Map | optional | Optional close frame {:code Int :reason String} |
Any(server/close-websocket ws {:code 1000 :reason "bye"})coerce-map-to-struct#
Coerces and validates a raw input map into an instance of `struct-type`, returning `ValidationErrors` on failure.
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-map | Any | required | — |
struct-type | Any | required | — |
Anycoerce-param-value#
Coerces a raw HTTP/query parameter string into the target `type-name` and validates constraints.
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-value | Any | required | — |
type-name | Any | required | — |
constraints | Any | required | — |
Anycompile-template#
Pre-compiles a route path template into an optimized token structure. Segments are tokenized into :literal, :param, or :wildcard.
| Parameter | Type | Optional | Description |
|---|---|---|---|
path-template | Any | required | — |
name | Any | required | — |
Anyconstruct-app-config#
Builds app config from process env vars and a fallback config data file.
| Parameter | Type | Optional | Description |
|---|---|---|---|
env-defaults-path | Any | required | — |
Anyconstruct-app-config-from-env#
Builds app config by preferring env values and falling back to defaults.
| Parameter | Type | Optional | Description |
|---|---|---|---|
current-env | Any | required | — |
env-defaults | Any | required | — |
Anycontent-type-of#
Returns the `Content-Type` header value of an HTTP message.
| Parameter | Type | Optional | Description |
|---|---|---|---|
msg | Map | required | HTTP request or response Map |
default | Any | optional | Optional default value |
Any(server/content-type-of req)decode-form-value#
Decodes a single form-urlencoded field value.
| Parameter | Type | Optional | Description |
|---|---|---|---|
value | Any | required | — |
Anyform-of#
Parses an `application/x-www-form-urlencoded` or `multipart/form-data` body into a field Map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Map | required | Incoming HTTP request Map |
Any(let fields (server/form-of req))get-bearer-token#
Extracts the bearer token from an HTTP `Authorization: Bearer ...` header, or `()` if absent/invalid.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyget-flash#
Reads and decodes flash data from request cookies.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyget-header#
Direct zero-allocation native Rust header and URI lookups.
| Parameter | Type | Optional | Description |
|---|---|---|---|
msg | Map | required | HTTP request or response Map |
name | String | KeySymbol | required | Case-insensitive header name |
default | Any | optional | Optional default value |
Any(server/header-of req "authorization")get-path-param#
Returns matched route path parameter `name` on `req`, falling back to `default-val`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
name | Any | required | — |
default-val | Any | required | — |
Anyget-path-param-int#
Parses matched route path parameter `name` as an `Int`, falling back to `default-val`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
name | Any | required | — |
default-val | Any | required | — |
Anyget-query-param#
Returns URL query parameter `name` from `req`, falling back to `default-val`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
name | Any | required | — |
default-val | Any | required | — |
Anyget-query-param-bool#
Parses URL query parameter `name` as a `Bool` (`true`/`false`/`1`/`0`), falling back to `default-val`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
name | Any | required | — |
default-val | Any | required | — |
Anyget-query-param-int#
Parses URL query parameter `name` as an `Int`, falling back to `default-val`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
name | Any | required | — |
default-val | Any | required | — |
Anyhas-flash?#
Returns true if the request contains a `_flash=` cookie header without decoding it.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyheader-map#
Normalizes a map of HTTP headers so all keys are lowercase strings for O(1) lookup.
| Parameter | Type | Optional | Description |
|---|---|---|---|
headers | Any | required | — |
Anyinterpolate-template#
Interpolates parameters into a pre-compiled route template. Consumed parameters are removed from the candidate pool; remaining parameters are appended to the URL as a query string.
| Parameter | Type | Optional | Description |
|---|---|---|---|
compiled | Any | required | — |
params | Any | required | — |
Anyis-delete?#
Returns `true` when the request method is `"DELETE"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-fetch?#
Returns `true` if the request carries `X-Requested-With: fetch`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-get?#
Request method and content inspectors Returns `true` when the request method is `"GET"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-head?#
Returns `true` when the request method is `"HEAD"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-json-request?#
Returns `true` if `Accept` prefers JSON or `Content-Type` starts with `application/json`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-options?#
Returns `true` when the request method is `"OPTIONS"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-patch?#
Returns `true` when the request method is `"PATCH"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-post?#
Returns `true` when the request method is `"POST"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-put?#
Returns `true` when the request method is `"PUT"`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyis-response-map?#
Returns whether `res` is an HTTP response map with an integer status code.
| Parameter | Type | Optional | Description |
|---|---|---|---|
res | Any | required | — |
Anyis-safe-external-url#
Validates whether a URL is a safe public target and not an internal network or cloud metadata address (SSRF guard).
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-url | Any | required | — |
Anyis-safe-external-url?#
Validates whether a URL is a safe public target and not an internal network or cloud metadata address (SSRF guard).
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-url | Any | required | — |
Anyis-stage-slots-request?#
Returns `true` if the request asks for incremental Stage SPA slot fragments (`X-Stage-Slots: 1`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyjson-of#
Decodes the JSON body of an HTTP request or response Map into native Tangu data.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Map | required | Incoming HTTP request Map |
Any(let body (server/json-of req))merge-attrs#
Merges attribute Maps left-to-right while cleanly concatenating `:class` lists instead of replacing them.
| Parameter | Type | Optional | Description |
|---|---|---|---|
maps | Map | required | Attribute maps to merge left-to-right |
Any(repr-html/merge-attrs {:class "btn"} extra-attrs)parse-component-params#
Normalizes `#shtml` custom component parameters into `{:attrs Map :children Array}`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
params | Array | required | Variadic SHTML component body `[attrs? ...children]` |
Any(let {:attrs attrs :children children} (repr-html/parse-component-params params))path-of#
Extracts the decoded URI path segment from an incoming request Map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Map | required | Incoming HTTP request Map |
Any(let path (server/path-of req))query-of#
Parses URL query parameters into a Map (promoting repeated keys into Arrays).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Map | required | Incoming HTTP request Map |
Any(let q (server/query-of req))query-string-of#
Returns the raw URL query string (excluding `?`) from a request Map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Map | required | Incoming HTTP request Map |
Any(let qs (server/query-string-of req))read-body#
Reads and parses the request body according to its Content-Type (JSON, form-urlencoded, or multipart).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyread-form#
Reads and coerces a request's form body into `struct-type` (or returns the raw map if `struct-type` is omitted).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
struct-type | Any | required | — |
Anyread-json#
Decodes a JSON request body (optionally coercing and validating against `struct-type`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
struct-type | Any | required | — |
Anyread-query#
Parses URL query parameters (optionally coercing and validating against `struct-type`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
struct-type | Any | required | — |
Anyreceive-websocket-message#
Awaits and returns the next frame from a server WebSocket `{:type :text|:binary|:ping|:pong|:close :data ...}`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
channel | WS-Channel | required | Connected server WebSocket channel |
Any(let msg (server/receive-websocket-message ws))redirect#
Constructs an HTTP redirect response (`303 See Other` by default) to `uri`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
uri | Any | required | — |
status-or-headers | Any | required | — |
extra-headers | Any | required | — |
Anyredirect-with-flash#
Creates a redirect response with an ephemeral flash payload.
| Parameter | Type | Optional | Description |
|---|---|---|---|
url | Any | required | — |
data | Any | required | — |
Anyregister-named-routes#
Registers pre-compiled named routes into the package default registry.
| Parameter | Type | Optional | Description |
|---|---|---|---|
routes-map | Any | required | — |
Anyrespond-css#
Constructs a `200 OK` CSS HTTP response (`Content-Type: text/css`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
css | Any | required | — |
headers | Any | required | — |
Anyrespond-error#
Constructs a standardized structured JSON error response with status, code, and optional details.
| Parameter | Type | Optional | Description |
|---|---|---|---|
status | Any | required | — |
code-or-err | Any | required | — |
details-or-headers | Any | required | — |
extra-headers | Any | required | — |
Anyrespond-html#
Constructs a `200 OK` HTML HTTP response (or passes through an existing response map).
| Parameter | Type | Optional | Description |
|---|---|---|---|
html | Any | required | — |
headers | Any | required | — |
Anyrespond-json#
Serializes `data` as a JSON HTTP response with optional status code and headers.
| Parameter | Type | Optional | Description |
|---|---|---|---|
data | Any | required | — |
status-or-headers | Any | required | — |
extra-headers | Any | required | — |
Anyrespond-method-not-allowed#
Returns a 405 response with the Allow header set.
| Parameter | Type | Optional | Description |
|---|---|---|---|
allowed | Any | required | — |
req | Any | required | — |
Anyrespond-no-content#
Returns an empty `204 No Content` HTTP response with optional extra headers.
| Parameter | Type | Optional | Description |
|---|---|---|---|
headers | Any | required | — |
Anyrespond-not-found#
Returns the default 404 Not Found HTML or JSON response.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyrespond-stage-slots#
Emits a standardized Stage JSON slot payload with CDN Vary protection.
| Parameter | Type | Optional | Description |
|---|---|---|---|
payload | Any | required | — |
extra | Any | required | — |
Anyrespond-status#
Constructs an HTTP response with custom numeric `status`, body `raw-message`, and optional headers.
| Parameter | Type | Optional | Description |
|---|---|---|---|
status | Any | required | — |
raw-message | Any | required | — |
headers | Any | required | — |
Anyrespond-text#
Constructs a `200 OK` plain text response (`Content-Type: text/plain; charset=utf-8`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
text | Any | required | — |
headers | Any | required | — |
Anyrespond-xml#
Respond with XML content.
| Parameter | Type | Optional | Description |
|---|---|---|---|
xml | Any | required | — |
headers | Any | required | — |
Anyrouter#
Builds a trie-backed HTTP router handler from declarative route definitions, scopes, and middleware.
| Parameter | Type | Optional | Description |
|---|---|---|---|
route-defs | Any | optional | — |
Anysafe-origin#
Strictly compares a client-supplied origin against an expected origin, preventing prefix bypasses.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client-origin | Any | required | — |
expected-origin | Any | required | — |
Anysafe-origin?#
Strictly compares a client-supplied origin against an expected origin, preventing prefix bypasses.
| Parameter | Type | Optional | Description |
|---|---|---|---|
client-origin | Any | required | — |
expected-origin | Any | required | — |
Anysafe-referer-path#
Resolves a safe redirect path from the request Referer header, falling back to a default path. Verifies the Referer is either a safe relative path or belongs to the current request host / localhost.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
fallback-args | Any | optional | — |
Anysafe-relative-path#
Validates and returns a safe relative path slice, strictly preventing path traversal attacks. Rejects leading slashes, backslashes, null bytes, and traversal segments (".." or ".").
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-path | Any | required | — |
Anysanitize-return-to#
Sanitizes a return-to parameter to prevent open redirect vulnerabilities. Returns fallback (defaulting to "/") if raw-return-to is empty, invalid, or external.
| Parameter | Type | Optional | Description |
|---|---|---|---|
raw-return-to | Any | required | — |
fallback-args | Any | optional | — |
Anysend-sse-event#
Pushes an SSE event over `channel` to the connected client (returns `false` if disconnected).
| Parameter | Type | Optional | Description |
|---|---|---|---|
channel | SSE-Channel | required | Open SSE channel handle |
data | String | required | Event payload string |
options | Map | optional | Optional {:event :id :retry} |
Any(server/send-sse-event ch "ping" {:event "heartbeat"})send-websocket-message#
Sends a text or binary message over a connected server WebSocket channel.
| Parameter | Type | Optional | Description |
|---|---|---|---|
channel | WS-Channel | required | Connected server WebSocket channel |
data | String | Slab | required | Text or binary WebSocket frame |
Any(server/send-websocket-message ws "ok")serve#
Opinionated HTTP server launcher reading `HOST` and `PORT` environment variables, delegating to `/http/server/serve`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
handler | Any | required | — |
options | Any | required | — |
rt | Any | required | — |
Anysse-response#
Creates an HTTP Server-Sent Events streaming response descriptor.
| Parameter | Type | Optional | Description |
|---|---|---|---|
on_connect | Func | required | Callback `(Func channel ...)` emitting SSE events |
Any(server/sse-response (Func ch (server/send-sse-event ch "hello")))url-for#
Polymorphic reverse routing constructor: - (url-for name) - (url-for name params) - (url-for req name) - (url-for req name params) - (url-for registry name params)
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anyurl-for-with-registry#
Resolves a route name within an explicit named routes registry map.
| Parameter | Type | Optional | Description |
|---|---|---|---|
registry | Any | required | — |
name | Any | required | — |
params | Any | required | — |
Anyverify-webhook-signature#
Verifies an HMAC-SHA256 webhook signature header against the raw request body in constant time.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
secret | Any | required | — |
header-name | Any | required | — |
Anywebsocket-response#
Creates an HTTP 101 WebSocket upgrade response descriptor.
| Parameter | Type | Optional | Description |
|---|---|---|---|
on_connect | Func | required | WebSocket lifecycle callback `(Func ws ...)` |
Any(server/websocket-response (Func ws (server/send-websocket-message ws "hi")))with-header#
Returns a response with a single header added or updated in-place.
| Parameter | Type | Optional | Description |
|---|---|---|---|
resp | Any | required | — |
name | Any | required | — |
val | Any | required | — |
Anywith-headers#
Returns a response with multiple headers added or updated in-place.
| Parameter | Type | Optional | Description |
|---|---|---|---|
resp | Any | required | — |
extra-headers | Any | required | — |
Anywith-status#
Returns a response with the status code updated in-place.
| Parameter | Type | Optional | Description |
|---|---|---|---|
resp | Any | required | — |
status | Any | required | — |
Any