API reference

fast-twitch.middlewares.common

Complete generated reference for fast-twitch.middlewares.common

Wrapper contracts

(ns application.middleware
  (:require [fast-twitch.middlewares.common :as common]))

(defn handler [_]
  {:status 200 :headers {} :body "Hello"})

(def app
  (common/wrap-response handler
    (fn [response request]
      (common/assoc-header response "x-request-path" (:uri request)))))

wrap-request takes [handler request-fn], where the transform receives a request and returns its replacement, possibly through a Promise. wrap-response takes [handler response-fn], where the transform receives [normalized-response original-request]. In wrap-request-response, request-fn runs first and response-fn sees that transformed request. All support the normal and callback handler contracts.

Native Responses are normalized before response transforms. Callback delivery is Promise-aware and settles once through respond/raise; returning a value from the underlying callback handler does not substitute for delivery.

Headers and conversion

header-value and has-header? receive a headers map and name. assoc-header receives a response map, name and value. append-header receives a headers map, name and value and preserves repeated values; remove-headers receives headers and names. These are different input shapes, despite similar names.

ft->fetch-request converts Ring URL components and bodies; it is not the same outward description path as client/request! with :url and request-init settings. fetch-response->ft uses the plain Ring projection. Forwarding through the client uses the preserved-native carrier path instead. Fetch resource semantics · Middleware composition.

Upstream function reference

Shared helpers for header handling, request conversion, and middleware composition.

append-header

(append-header headers k v)

Function.

Appends a header value while preserving any existing header entries. Source

assoc-header

(assoc-header response k v)

Function.

Associates a header on a response map. Source

fetch-response->ft

(fetch-response->ft native)

Function. Source

ft->fetch-request

(ft->fetch-request m)

Function. Source

has-header?

(has-header? headers k)

Function.

Returns true when the given header is present. Source

header-key

(header-key k)

Function.

Normalizes a header name to a lowercase keyword. Source

header-value

(header-value headers k)

Function.

Looks up a header value without caring about header name casing. Source

headers->entries

(headers->entries headers)

Function.

Converts a header map into name/value entry pairs for Fetch APIs. Source

headers->map

(headers->map headers)

Function.

Converts a Fetch Headers instance into a plain Clojure map. Source

promise

(promise x)

Function.

Wraps x in a resolved JavaScript promise. Source

promise?

(promise? x)

Function.

Returns true when x behaves like a JavaScript promise. Source

remove-headers

(remove-headers headers names)

Function.

Removes all headers whose names match the supplied collection. Source

request-url

(request-url m)

Function.

Builds a full request URL string from a Ring request map. Source

wrap-request

(wrap-request handler request-fn)

Function.

Wraps a handler with a request transformation that may be asynchronous. Source

wrap-request-response

(wrap-request-response handler request-fn response-fn)

Function.

Wraps a handler with coordinated request and response transformations. Source

wrap-response

(wrap-response handler response-fn)

Function.

Wraps a handler with a response transformation that sees the original request. Source


Source revision a4eb73f96836d034c7a24fe09dc7d51e4c581f64

Built with Fast-Twitch · Integrant · Datastar

Search documentation

Search pages and API symbols

Start hereWelcome to Fast-TwitchRing HTTP applications and configured native clients and transports in ClojureScript.Start hereGetting startedCompile and run your first Fast-Twitch server.Core conceptsRequest & responseUnderstand the maps at the center of a Fast-Twitch application.Core conceptsRoutingMatch URL patterns and compose handlers.Core conceptsMiddlewareWrap handlers with focused request and response behavior.GuidesHTML & IntegrantCompose a UI system with Integrant and render Hiccup.