HTTP side-effect module for Relm built on the Fetch API.
Provides core/fx side effects for making asynchronous HTTP requests (::fetch)
and aborting active requests (::abort). Handles JSON serialization, query parameter
encoding, response header parsing, response body decoding based on Content-Type,
request timeouts, and error handling with automated message dispatching back into Relm.
HTTP side-effect module for Relm built on the Fetch API. Provides `core/fx` side effects for making asynchronous HTTP requests (`::fetch`) and aborting active requests (`::abort`). Handles JSON serialization, query parameter encoding, response header parsing, response body decoding based on Content-Type, request timeouts, and error handling with automated message dispatching back into Relm.
(->reader reader-or-kw)Normalizes reader configurations, resolving keyword shortcuts like :json to reader maps.
Normalizes reader configurations, resolving keyword shortcuts like `:json` to reader maps.
(->seq x)Ensures x is wrapped in a sequential collection. Returns x if sequential, otherwise [x].
Ensures `x` is wrapped in a sequential collection. Returns `x` if sequential, otherwise `[x]`.
(->str x)Converts x into a String. Returns the name if keyword or symbol, otherwise (str x).
Converts `x` into a String. Returns the name if keyword or symbol, otherwise `(str x)`.
(abort {:keys [request-id]})Aborts an in-flight HTTP request identified by :request-id.
Aborts an in-flight HTTP request identified by `:request-id`.
(abort-fx effect)Executes one or more abort effect specifications.
Executes one or more abort effect specifications.
(body-problem-handler dom-event
{:keys [request-id on-failure]
:or {on-failure [:relm.http/fetch-no-on-failure]}}
response
{:keys [reader-kw] :as _reader}
js-error)Dispatches failure event when decoding or parsing the response body fails.
Dispatches failure event when decoding or parsing the response body fails.
(body-success-handler dom-event
{:keys [request-id on-success on-failure]
:or {on-success [:relm.http/fetch-no-on-success]
on-failure [:relm.http/fetch-no-on-failure]}}
response
{:keys [reader-kw reader-fn] :as _reader}
js-body)Dispatches success event after response body has been read and processed.
Dispatches success event after response body has been read and processed.
Default reader configuration for JSON response payloads. Converts parsed JavaScript objects into Clojure maps with keywordized keys.
Default reader configuration for JSON response payloads. Converts parsed JavaScript objects into Clojure maps with keywordized keys.
Default mapping of Content-Type header patterns to response body reader keywords.
Default mapping of Content-Type header patterns to response body reader keywords.
Default fallback reader configuration for text/plain response payloads. Returns the raw string response body unmodified.
Default fallback reader configuration for text/plain response payloads. Returns the raw string response body unmodified.
(encode-kv k v)URI-encodes a key-value pair as key=value string.
URI-encodes a key-value pair as `key=value` string.
(fetch dom-event
{:keys [url timeout params request-id on-request-id abort-signal]
:as request
:or {request-id (keyword (gensym "fetch-fx-"))}})Initializes and executes an HTTP Fetch request. Options map:
:url URL string to fetch:method HTTP method keyword/string (:get, :post, :put, etc.):params Query parameters map:headers HTTP headers map:body Request body payload:request-content-type Content type shortcut (e.g. :json):timeout Request timeout in milliseconds:request-id Unique request ID keyword (auto-generated if omitted):on-request-id Callback message vector receiving the generated request-id ([::msg ...]):on-success Message vector dispatched on successful response [::msg ...]:on-failure Message vector dispatched on error [::msg ...]Initializes and executes an HTTP Fetch request. Options map: - `:url` URL string to fetch - `:method` HTTP method keyword/string (`:get`, `:post`, `:put`, etc.) - `:params` Query parameters map - `:headers` HTTP headers map - `:body` Request body payload - `:request-content-type` Content type shortcut (e.g. `:json`) - `:timeout` Request timeout in milliseconds - `:request-id` Unique request ID keyword (auto-generated if omitted) - `:on-request-id` Callback message vector receiving the generated `request-id` (`[::msg ...]`) - `:on-success` Message vector dispatched on successful response `[::msg ...]` - `:on-failure` Message vector dispatched on error `[::msg ...]`
(fetch-fx event effect)Executes one or more fetch effect specifications.
Executes one or more fetch effect specifications.
(headers->js headers)Converts a ClojureScript map of headers into a JavaScript Headers instance.
Converts a ClojureScript map of headers into a JavaScript `Headers` instance.
(js-error->problem js-error)Maps JavaScript fetch errors/exceptions to relm problem keywords (:timeout, :aborted, :fetch).
Maps JavaScript fetch errors/exceptions to relm problem keywords (`:timeout`, `:aborted`, `:fetch`).
(js-headers->clj js-headers)Converts a JavaScript Headers object into a ClojureScript map with keywordized keys.
Converts a JavaScript `Headers` object into a ClojureScript map with keywordized keys.
(js-response->clj js-response)Converts a JavaScript Response object into a ClojureScript map containing response metadata.
Converts a JavaScript `Response` object into a ClojureScript map containing response metadata.
(params->str params)Encodes a map of query parameters into a URL query string prefixed with ?.
Supports vector values as repeated query parameters.
Encodes a map of query parameters into a URL query string prefixed with `?`. Supports vector values as repeated query parameters.
(request->js-init {:keys [method headers request-content-type body mode
credentials cache redirect referrer integrity]}
abort-signal)Builds the options configuration object (JavaScript object) passed as the second argument to js/fetch.
Builds the options configuration object (JavaScript object) passed as the second argument to `js/fetch`.
Registry atom tracking active JavaScript AbortController instances indexed by request-id.
Registry atom tracking active JavaScript AbortController instances indexed by `request-id`.
(response->reader {:keys [response-content-types response-content-type]}
response)Selects the appropriate response body reader based on the response's Content-Type header.
Returns a reader map with keys:
:reader-kw Method to invoke on the JS Response (:json, :text, :blob, :array-buffer, :form-data):reader-fn Transformation function applied to the decoded bodySelects the appropriate response body reader based on the response's `Content-Type` header. Returns a reader map with keys: - `:reader-kw` Method to invoke on the JS Response (`:json`, `:text`, `:blob`, `:array-buffer`, `:form-data`) - `:reader-fn` Transformation function applied to the decoded body
(response-problem-handler dom-event
{:keys [request-id on-failure]
:or {on-failure [:relm.http/fetch-no-on-failure]}}
js-error)Dispatches failure event when network transport, timeout, or abort errors occur.
Dispatches failure event when network transport, timeout, or abort errors occur.
(response-success-handler dom-event request js-response)Reads the JS Response stream according to the resolved reader and forwards to body handlers.
Reads the JS `Response` stream according to the resolved reader and forwards to body handlers.
(timeout-race js-promise timeout)Wraps a JavaScript Promise in a timeout race that rejects with :timeout after timeout milliseconds.
Wraps a JavaScript `Promise` in a timeout race that rejects with `:timeout` after `timeout` milliseconds.
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 |