# Module /web/app

Core full-stack web application primitives: cookies, flash messages, query/form params, responses, and trie router.

```tangu
(use /web/app)
```

## Constants

### *request*

`Constant (Any)`

Dynamic variable bound to the active HTTP request inside request handlers.

## Functions & symbols

### Cookie

`(Cookie params)`

Cookie {
name
value
path
expires
domain
secure
HttpOnly
}

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `params` | `Any` | no | — |

### add-classes

`(add-classes attrs ...classes) -> None`

Mutates `attrs:class` in place by appending `classes` without overwriting existing classes.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `attrs` | `Map` | no | Mutable attributes Map |
| `classes` | `Any` | no | One or more class names/arrays/maps |

```tangu
(repr-html/add-classes attrs "card" "elevated")
```

### attach-cookie

`(attach-cookie resp cookie)`

Adds a cookie to an existing response.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |
| `cookie` | `Any` | no | — |

### build-query-string

`(build-query-string query-map)`

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` | no | — |

### clear-flash-cookie

`(clear-flash-cookie resp)`

Attaches a Set-Cookie header to clear the flash cookie on response.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |

### clear-named-routes

`(clear-named-routes)`

Clears all registered routes in the package default registry (useful for testing).

### client-ip-of

`(client-ip-of req)`

Resolves the client IP address from X-Forwarded-For, X-Real-IP, or remote-addr.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### close-websocket

`(close-websocket channel [options]) -> None`

Cleanly closes a server WebSocket connection with an optional close status code and reason.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `WS-Channel` | no | Connected server WebSocket channel |
| `options` | `Map` | yes | Optional close frame {:code Int :reason String} |

```tangu
(server/close-websocket ws {:code 1000 :reason "bye"})
```

### coerce-map-to-struct

`(coerce-map-to-struct raw-map struct-type)`

Coerces and validates a raw input map into an instance of `struct-type`, returning `ValidationErrors` on failure.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `raw-map` | `Any` | no | — |
| `struct-type` | `Any` | no | — |

### coerce-param-value

`(coerce-param-value raw-value type-name constraints)`

Coerces a raw HTTP/query parameter string into the target `type-name` and validates constraints.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `raw-value` | `Any` | no | — |
| `type-name` | `Any` | no | — |
| `constraints` | `Any` | no | — |

### compile-template

`(compile-template path-template name)`

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` | no | — |
| `name` | `Any` | no | — |

### construct-app-config

`(construct-app-config env-defaults-path)`

Builds app config from process env vars and a fallback config data file.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `env-defaults-path` | `Any` | no | — |

### construct-app-config-from-env

`(construct-app-config-from-env current-env env-defaults)`

Builds app config by preferring env values and falling back to defaults.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `current-env` | `Any` | no | — |
| `env-defaults` | `Any` | no | — |

### content-type-of

`(content-type-of msg [default]) -> (Or String None)`

Returns the `Content-Type` header value of an HTTP message.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `msg` | `Map` | no | HTTP request or response Map |
| `default` | `Any` | yes | Optional default value |

```tangu
(server/content-type-of req)
```

### cookie->header

`(cookie->header cookie)`

Serializes a Cookie struct or map into a `Set-Cookie` HTTP header string.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `cookie` | `Any` | no | — |

### cookie-base64-decode

`(cookie-base64-decode encoded)`

Restores base64 padding before decoding a cookie payload.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `encoded` | `Any` | no | — |

### cookie-base64-encode

`(cookie-base64-encode text)`

Removes base64 padding so cookie values survive parser round-trips.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `Any` | no | — |

### cookies-of

`(get-cookies req)`

Parses the incoming request `Cookie` header into a decoded `{name value}` map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### decode-form-value

`(decode-form-value value)`

Decodes a single form-urlencoded field value.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `value` | `Any` | no | — |

### form-of

`(form-of req) -> Map`

Parses an `application/x-www-form-urlencoded` or `multipart/form-data` body into a field Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let fields (server/form-of req))
```

### get-bearer-token

`(get-bearer-token req)`

Extracts the bearer token from an HTTP `Authorization: Bearer ...` header, or `()` if absent/invalid.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### get-cookie

`(get-cookie req name default-val)`

Returns the value of cookie `name` from the request, or `default-val` if absent.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### get-cookies

`(get-cookies req)`

Parses the incoming request `Cookie` header into a decoded `{name value}` map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### get-flash

`(get-flash req)`

Reads and decodes flash data from request cookies.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### get-header

`(header-of msg name [default]) -> (Or String None)`

Direct zero-allocation native Rust header and URI lookups.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `msg` | `Map` | no | HTTP request or response Map |
| `name` | `String | KeySymbol` | no | Case-insensitive header name |
| `default` | `Any` | yes | Optional default value |

```tangu
(server/header-of req "authorization")
```

### get-path-param

`(get-path-param req name default-val)`

Returns matched route path parameter `name` on `req`, falling back to `default-val`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### get-path-param-int

`(get-path-param-int req name default-val)`

Parses matched route path parameter `name` as an `Int`, falling back to `default-val`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### get-query-param

`(get-query-param req name default-val)`

Returns URL query parameter `name` from `req`, falling back to `default-val`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### get-query-param-bool

`(get-query-param-bool req name default-val)`

Parses URL query parameter `name` as a `Bool` (`true`/`false`/`1`/`0`), falling back to `default-val`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### get-query-param-int

`(get-query-param-int req name default-val)`

Parses URL query parameter `name` as an `Int`, falling back to `default-val`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `name` | `Any` | no | — |
| `default-val` | `Any` | no | — |

### has-flash?

`(has-flash? req)`

Returns true if the request contains a `_flash=` cookie header without decoding it.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### header-map

`(header-map headers)`

Normalizes a map of HTTP headers so all keys are lowercase strings for O(1) lookup.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `headers` | `Any` | no | — |

### interpolate-template

`(interpolate-template compiled params)`

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` | no | — |
| `params` | `Any` | no | — |

### is-delete?

`(is-delete? req)`

Returns `true` when the request method is `"DELETE"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-fetch?

`(is-fetch? req)`

Returns `true` if the request carries `X-Requested-With: fetch`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-get?

`(is-get? req)`

Request method and content inspectors
Returns `true` when the request method is `"GET"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-head?

`(is-head? req)`

Returns `true` when the request method is `"HEAD"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-json-request?

`(is-json-request? req)`

Returns `true` if `Accept` prefers JSON or `Content-Type` starts with `application/json`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-options?

`(is-options? req)`

Returns `true` when the request method is `"OPTIONS"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-patch?

`(is-patch? req)`

Returns `true` when the request method is `"PATCH"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-post?

`(is-post? req)`

Returns `true` when the request method is `"POST"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-put?

`(is-put? req)`

Returns `true` when the request method is `"PUT"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-response-map?

`(is-response-map? res)`

Returns whether `res` is an HTTP response map with an integer status code.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `res` | `Any` | no | — |

### is-safe-external-url

`(is-safe-external-url? raw-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` | no | — |

### is-safe-external-url?

`(is-safe-external-url? raw-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` | no | — |

### is-stage-slots-request?

`(is-stage-slots-request? req)`

Returns `true` if the request asks for incremental Stage SPA slot fragments (`X-Stage-Slots: 1`).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### json-of

`(json-of msg) -> Any`

Decodes the JSON body of an HTTP request or response Map into native Tangu data.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let body (server/json-of req))
```

### merge-attrs

`(merge-attrs ...maps) -> Map`

Merges attribute Maps left-to-right while cleanly concatenating `:class` lists instead of replacing them.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `maps` | `Map` | no | Attribute maps to merge left-to-right |

```tangu
(repr-html/merge-attrs {:class "btn"} extra-attrs)
```

### parse-component-params

`(parse-component-params params-arr) -> Map`

Normalizes `#shtml` custom component parameters into `{:attrs Map :children Array}`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `params` | `Array` | no | Variadic SHTML component body `[attrs? ...children]` |

```tangu
(let {:attrs attrs :children children} (repr-html/parse-component-params params))
```

### path-of

`(path-of req) -> String`

Extracts the decoded URI path segment from an incoming request Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let path (server/path-of req))
```

### query-of

`(query-of req) -> Map`

Parses URL query parameters into a Map (promoting repeated keys into Arrays).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let q (server/query-of req))
```

### query-string-of

`(query-string-of req) -> String`

Returns the raw URL query string (excluding `?`) from a request Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let qs (server/query-string-of req))
```

### read-body

`(read-body req)`

Reads and parses the request body according to its Content-Type (JSON, form-urlencoded, or multipart).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### read-form

`(read-form req struct-type)`

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` | no | — |
| `struct-type` | `Any` | no | — |

### read-json

`(read-json req struct-type)`

Decodes a JSON request body (optionally coercing and validating against `struct-type`).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `struct-type` | `Any` | no | — |

### read-json-cookie

`(read-json-cookie req cookie-name)`

Reads and decodes a JSON payload stored in a cookie.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `cookie-name` | `Any` | no | — |

### read-query

`(read-query req struct-type)`

Parses URL query parameters (optionally coercing and validating against `struct-type`).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `struct-type` | `Any` | no | — |

### receive-websocket-message

`(receive-websocket-message channel) -> (Or Map None)`

Awaits and returns the next frame from a server WebSocket `{:type :text|:binary|:ping|:pong|:close :data ...}`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `WS-Channel` | no | Connected server WebSocket channel |

```tangu
(let msg (server/receive-websocket-message ws))
```

### redirect

`(redirect uri status-or-headers extra-headers)`

Constructs an HTTP redirect response (`303 See Other` by default) to `uri`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `uri` | `Any` | no | — |
| `status-or-headers` | `Any` | no | — |
| `extra-headers` | `Any` | no | — |

### redirect-with-flash

`(redirect-with-flash url data)`

Creates a redirect response with an ephemeral flash payload.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `url` | `Any` | no | — |
| `data` | `Any` | no | — |

### register-named-routes

`(register-named-routes routes-map)`

Registers pre-compiled named routes into the package default registry.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `routes-map` | `Any` | no | — |

### remove-cookie-header

`(remove-cookie-header headers name)`

Appends an expired `Set-Cookie` header instructing the browser to clear cookie `name`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `headers` | `Any` | no | — |
| `name` | `Any` | no | — |

### respond-css

`(respond-css css headers)`

Constructs a `200 OK` CSS HTTP response (`Content-Type: text/css`).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `css` | `Any` | no | — |
| `headers` | `Any` | no | — |

### respond-error

`(respond-error status code-or-err details-or-headers extra-headers)`

Constructs a standardized structured JSON error response with status, code, and optional details.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `status` | `Any` | no | — |
| `code-or-err` | `Any` | no | — |
| `details-or-headers` | `Any` | no | — |
| `extra-headers` | `Any` | no | — |

### respond-html

`(respond-html html headers)`

Constructs a `200 OK` HTML HTTP response (or passes through an existing response map).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `html` | `Any` | no | — |
| `headers` | `Any` | no | — |

### respond-json

`(respond-json data status-or-headers extra-headers)`

Serializes `data` as a JSON HTTP response with optional status code and headers.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `data` | `Any` | no | — |
| `status-or-headers` | `Any` | no | — |
| `extra-headers` | `Any` | no | — |

### respond-method-not-allowed

`(respond-method-not-allowed allowed req)`

Returns a 405 response with the Allow header set.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `allowed` | `Any` | no | — |
| `req` | `Any` | no | — |

### respond-no-content

`(respond-no-content headers)`

Returns an empty `204 No Content` HTTP response with optional extra headers.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `headers` | `Any` | no | — |

### respond-not-found

`(respond-not-found req)`

Returns the default 404 Not Found HTML or JSON response.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### respond-stage-slots

`(respond-stage-slots payload extra)`

Emits a standardized Stage JSON slot payload with CDN Vary protection.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `payload` | `Any` | no | — |
| `extra` | `Any` | no | — |

### respond-status

`(respond-status status raw-message headers)`

Constructs an HTTP response with custom numeric `status`, body `raw-message`, and optional headers.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `status` | `Any` | no | — |
| `raw-message` | `Any` | no | — |
| `headers` | `Any` | no | — |

### respond-text

`(respond-text text headers)`

Constructs a `200 OK` plain text response (`Content-Type: text/plain; charset=utf-8`).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `Any` | no | — |
| `headers` | `Any` | no | — |

### respond-xml

`(respond-xml xml headers)`

Respond with XML content.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `xml` | `Any` | no | — |
| `headers` | `Any` | no | — |

### router

`(router ...route-defs)`

Builds a trie-backed HTTP router handler from declarative route definitions, scopes, and middleware.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `route-defs` | `Any` | yes | — |

### safe-origin

`(safe-origin? client-origin expected-origin)`

Strictly compares a client-supplied origin against an expected origin, preventing prefix bypasses.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `client-origin` | `Any` | no | — |
| `expected-origin` | `Any` | no | — |

### safe-origin?

`(safe-origin? client-origin expected-origin)`

Strictly compares a client-supplied origin against an expected origin, preventing prefix bypasses.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `client-origin` | `Any` | no | — |
| `expected-origin` | `Any` | no | — |

### safe-referer-path

`(safe-referer-path req ...fallback-args)`

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` | no | — |
| `fallback-args` | `Any` | yes | — |

### safe-relative-path

`(safe-relative-path raw-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` | no | — |

### sanitize-return-to

`(sanitize-return-to raw-return-to ...fallback-args)`

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` | no | — |
| `fallback-args` | `Any` | yes | — |

### send-sse-event

`(send-sse-event channel data [options]) -> Bool`

Pushes an SSE event over `channel` to the connected client (returns `false` if disconnected).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `SSE-Channel` | no | Open SSE channel handle |
| `data` | `String` | no | Event payload string |
| `options` | `Map` | yes | Optional {:event :id :retry} |

```tangu
(server/send-sse-event ch "ping" {:event "heartbeat"})
```

### send-websocket-message

`(send-websocket-message channel data) -> None`

Sends a text or binary message over a connected server WebSocket channel.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `WS-Channel` | no | Connected server WebSocket channel |
| `data` | `String | Slab` | no | Text or binary WebSocket frame |

```tangu
(server/send-websocket-message ws "ok")
```

### serve

`(serve handler options rt)`

Opinionated HTTP server launcher reading `HOST` and `PORT` environment variables, delegating to `/http/server/serve`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `handler` | `Any` | no | — |
| `options` | `Any` | no | — |
| `rt` | `Any` | no | — |

### set-cookie-header

`(set-cookie-header headers cookie)`

Appends the cookie to the response headers. If Set-Cookie is already present,
it converts the value to an Array and appends the new cookie, supporting multiple
cookies in a single response via multi-value headers.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `headers` | `Any` | no | — |
| `cookie` | `Any` | no | — |

### sse-response

`(sse-response on-connect) -> Map`

Creates an HTTP Server-Sent Events streaming response descriptor.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `on_connect` | `Func` | no | Callback `(Func channel ...)` emitting SSE events |

```tangu
(server/sse-response (Func ch (server/send-sse-event ch "hello")))
```

### url-for

`(url-for ...args)`

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` | yes | — |

### url-for-with-registry

`(url-for-with-registry registry name params)`

Resolves a route name within an explicit named routes registry map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `registry` | `Any` | no | — |
| `name` | `Any` | no | — |
| `params` | `Any` | no | — |

### verify-webhook-signature

`(verify-webhook-signature req secret header-name)`

Verifies an HMAC-SHA256 webhook signature header against the raw request body in constant time.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |
| `secret` | `Any` | no | — |
| `header-name` | `Any` | no | — |

### websocket-response

`(websocket-response on-connect) -> Map`

Creates an HTTP 101 WebSocket upgrade response descriptor.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `on_connect` | `Func` | no | WebSocket lifecycle callback `(Func ws ...)` |

```tangu
(server/websocket-response (Func ws (server/send-websocket-message ws "hi")))
```

### with-cookie

`(attach-cookie resp cookie)`

Adds a cookie to an existing response.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |
| `cookie` | `Any` | no | — |

### with-header

`(with-header resp name val)`

Returns a response with a single header added or updated in-place.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |
| `name` | `Any` | no | — |
| `val` | `Any` | no | — |

### with-headers

`(with-headers resp extra-headers)`

Returns a response with multiple headers added or updated in-place.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |
| `extra-headers` | `Any` | no | — |

### with-status

`(with-status resp status)`

Returns a response with the status code updated in-place.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `resp` | `Any` | no | — |
| `status` | `Any` | no | — |
