Constructors for the responses a handler writes most: the Ring maps the
base reads, with nothing else in them. ok carries Hiccup for the route's
layouts; see-other is the redirect after a classic form. There is no
not-found or forbidden here on purpose: those are error/throw!, so
they reach the error renderer and not the layout stack.
Constructors for the responses a handler writes most: the Ring maps the base reads, with nothing else in them. `ok` carries Hiccup for the route's layouts; `see-other` is the redirect after a classic form. There is no `not-found` or `forbidden` here on purpose: those are `error/throw!`, so they reach the error renderer and not the layout stack.
(attachment body filename)(attachment body filename {:keys [content-type inline?] :as opts})A download: body — bytes, a stream, a file — to be saved under filename. With two
arguments it is sent as application/octet-stream and never shown, whatever type it
was uploaded with (since 0.17.0). A blank name is refused: a download with none is
saved under whatever the browser makes of the URL.
With options (since 0.22.0), :content-type is the type it is sent as, and :inline? true lets the browser show it in place — a PDF the host has checked is one — under its
name, as a page of its own: inside a frame of the host's page only where the security
headers let the page be framed (:frame-options, a CSP's frame-ancestors). Only
application/pdf, image/png, image/jpeg, image/gif and image/webp, spelt
exactly, may be shown in place: an SVG or an HTML document would run its script in
this origin, so anything else with :inline? is refused at the call, as is a type that
is no media type or an option it does not take. A refused stream is closed.
No caching rule is imposed here. A response to a request with a subject or a session
is already no-store (gate/wrap-subject); a file of somebody's reached with neither —
by a credential in its URL, from a mail — is the host's to mark no-store.
A download: `body` — bytes, a stream, a file — to be saved under `filename`. With two arguments it is sent as `application/octet-stream` and never shown, whatever type it was uploaded with (since 0.17.0). A blank name is refused: a download with none is saved under whatever the browser makes of the URL. With options (since 0.22.0), `:content-type` is the type it is sent as, and `:inline? true` lets the browser show it in place — a PDF the host has checked is one — under its name, as a page of its own: inside a frame of the host's page only where the security headers let the page be framed (`:frame-options`, a CSP's `frame-ancestors`). Only `application/pdf`, `image/png`, `image/jpeg`, `image/gif` and `image/webp`, spelt exactly, may be shown in place: an SVG or an HTML document would run its script in this origin, so anything else with `:inline?` is refused at the call, as is a type that is no media type or an option it does not take. A refused stream is closed. No caching rule is imposed here. A response to a request with a subject or a session is already `no-store` (`gate/wrap-subject`); a file of somebody's reached with neither — by a credential in its URL, from a mail — is the host's to mark `no-store`.
(health ready?)A handler for a health probe, for :sessionless: ready? is asked on every request,
and answers 200 ok when it is truthy and 503 when it is not or throws — the throw
logged, since a probe that says only 503 would leave the operator guessing. Plain text,
uncached, and nothing else in the body: a probe is public, and the state behind it is
the operator's to read, not the internet's.
A handler for a health probe, for `:sessionless`: `ready?` is asked on every request, and answers 200 `ok` when it is truthy and 503 when it is not or throws — the throw logged, since a probe that says only 503 would leave the operator guessing. Plain text, uncached, and nothing else in the body: a probe is public, and the state behind it is the operator's to read, not the internet's.
(ok body)(ok body {:keys [slots height]}){:status 200 :body body}. :slots becomes :wb/slots, what the layouts
receive besides :content and :request; :height becomes :wb/height,
how many layouts render (SPEC §12). An option not given stays absent, so
the renderer's own defaults apply.
`{:status 200 :body body}`. `:slots` becomes `:wb/slots`, what the layouts
receive besides `:content` and `:request`; `:height` becomes `:wb/height`,
how many layouts render (SPEC §12). An option not given stays absent, so
the renderer's own defaults apply.(see-other location)The redirect after a POST: a 303 makes the browser GET location, and an
empty body is what the gate's own redirect carries.
The redirect after a POST: a 303 makes the browser GET `location`, and an empty body is what the gate's own redirect carries.
(unprocessable body)(unprocessable body opts)ok with status 422: what the handler that refused a request drew, with its reason.
Three callers, all legitimate:
htmx.config.responseHandling said so);fetch and swaps the answer in itself: it is no htmx
request, so the layouts render unless {:height 0} says otherwise;dev.arkaitz.web-base/rerender is the other road for a classic form: it runs the
page's own GET, so the POST builds nothing, at the cost of that GET's reads.`ok` with status 422: what the handler that refused a request drew, with its reason.
Three callers, all legitimate:
- an htmx form that swaps only itself, where re-running the page's GET would render
more than the target (htmx 4 swaps a 422; htmx 2 swapped no 4xx unless
`htmx.config.responseHandling` said so);
- a page's script that sends with `fetch` and swaps the answer in itself: it is no htmx
request, so the layouts render unless `{:height 0}` says otherwise;
- a classic form whose POST draws the page itself, from the view its GET shares — the
refused values at hand, no second read.
`dev.arkaitz.web-base/rerender` is the other road for a classic form: it runs the
page's own GET, so the POST builds nothing, at the cost of that GET's reads.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |