Liking cljdoc? Tell your friends :D

relm.http

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.
raw docstring

->readercljs

(->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.
raw docstring

->seqcljs

(->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]`.
raw docstring

->strcljs

(->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)`.
raw docstring

abortcljs

(abort {:keys [request-id]})

Aborts an in-flight HTTP request identified by :request-id.

Aborts an in-flight HTTP request identified by `:request-id`.
raw docstring

abort-fxcljs

(abort-fx effect)

Executes one or more abort effect specifications.

Executes one or more abort effect specifications.
raw docstring

body-problem-handlercljs

(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.
raw docstring

body-success-handlercljs

(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.
raw docstring

default-json-readercljs

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.
raw docstring

default-response-content-typescljs

Default mapping of Content-Type header patterns to response body reader keywords.

Default mapping of Content-Type header patterns to response body reader keywords.
raw docstring

default-text-readercljs

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.
raw docstring

encode-kvcljs

(encode-kv k v)

URI-encodes a key-value pair as key=value string.

URI-encodes a key-value pair as `key=value` string.
raw docstring

fetchcljs

(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 ...]`
raw docstring

fetch-fxcljs

(fetch-fx event effect)

Executes one or more fetch effect specifications.

Executes one or more fetch effect specifications.
raw docstring

headers->jscljs

(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.
raw docstring

js-error->problemcljs

(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`).
raw docstring

js-headers->cljcljs

(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.
raw docstring

js-response->cljcljs

(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.
raw docstring

params->strcljs

(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.
raw docstring

request->js-initcljs

(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`.
raw docstring

request-id->js-abort-controllercljs

Registry atom tracking active JavaScript AbortController instances indexed by request-id.

Registry atom tracking active JavaScript AbortController instances indexed by `request-id`.
raw docstring

response->readercljs

(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 body
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 body
raw docstring

response-problem-handlercljs

(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.
raw docstring

response-success-handlercljs

(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.
raw docstring

timeout-racecljs

(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.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close