Liking cljdoc? Tell your friends :D

io.axrs.cljs-sync-request.core


*sync-request*cljs

Dynamic reference to the underlying Javascript sync-request module.

Note: sync-request is not bundled with cljs-sync-request. Refer [[compojure.core/set-sync-request!]]

Dynamic reference to the underlying Javascript [`sync-request`](https://github.com/ForbesLindesay/sync-request) module.

Note: `sync-request` is not bundled with `cljs-sync-request`. Refer [[compojure.core/set-sync-request!]]
sourceraw docstring

clj->jsoncljs

(clj->json e)

A no assumption clj->JSON encoding function used by all json-* request methods with a :body. Can be replaced by specifying :encode in the opts of any request method.

A no assumption clj->JSON encoding function used by all `json-*` request methods with a `:body`. Can be replaced by
specifying `:encode` in the `opts` of any request method.
sourceraw docstring

DELETEcljs

method used to perform a DELETE request

`method` used to perform a `DELETE` request
sourceraw docstring

GETcljs

method used to perform a GET request

`method` used to perform a `GET` request
sourceraw docstring

method used to perform a HEAD request

`method` used to perform a `HEAD` request
sourceraw docstring

json->cljcljs

(json->clj s)

A no assumption JSON->clj decoding function used by all json-* request methods decode a response :body. Can be replaced by specifying the :decode in the opts of any request method.

A no assumption JSON->clj decoding function used by all `json-*` request methods decode a response `:body`. Can be
replaced by specifying the `:decode` in the `opts` of any request method.
sourceraw docstring

json-deletecljs

(json-delete url)
(json-delete url {:as opts})

Performs a synchronous JSON DELETE request to the specified url

Performs a synchronous JSON DELETE request to the specified `url`
sourceraw docstring

json-getcljs

(json-get url)
(json-get url {:as opts})

Performs a synchronous JSON GET request to the specified url

Performs a synchronous JSON GET request to the specified `url`
sourceraw docstring

json-headcljs

(json-head url)
(json-head url {:as opts})

Performs a synchronous JSON HEAD request to the specified url

Performs a synchronous JSON HEAD request to the specified `url`
sourceraw docstring

json-postcljs

(json-post url body)
(json-post url body {:as opts})

Performs a synchronous JSON POST request to the specified url with a given edn body transformed into JSON

Performs a synchronous JSON POST request to the specified `url` with a given edn `body` transformed into JSON
sourceraw docstring

json-putcljs

(json-put url body)
(json-put url body {:as opts})

Performs a synchronous JSON PUT request to the specified url with a given edn body transformed into JSON

Performs a synchronous JSON PUT request to the specified `url` with a given edn `body` transformed into JSON
sourceraw docstring

POSTcljs

method used to perform a POST request

`method` used to perform a `POST` request
sourceraw docstring

PUTcljs

method used to perform a PUT request

`method` used to perform a `PUT` request
sourceraw docstring

requestcljs

(request method
         url
         {:keys [body] :as context}
         {:keys [encode decode inflate deflate]
          :or
            {encode identity decode identity inflate identity deflate identity}
          :as opts})

Performs a sync-request with an encoded body and inflated context. The returned {:keys [status body headers] :as response} is deflated and with a decoded body.

Refer to sync-request options for all available features of the context map including :timeout, :retry, :maxRetries, :qs, and more.

opts map

:encode - A function that takes the body from the context and transforms it before performing the request. Defaults to clj->json for JSON requests

:decode - A function that takes the body of the response and decodes it before returning a result. Defaults to json->clj for JSON requests

:inflate - A function that takes the full context and transforms it before performing the request.

:deflate - A function that takes the full response and transforms it before returning a result.

(request
  POST
  {:body {:id "123"} :headers {"Accept" "application/json"}}
  {:encode (fn [request-body] (assoc request-body :token "456"))
   :decode (fn [response-body] (-> response-body json->clj (assoc :response-time (js/Date.))))
   :inflate (fn [request] (assoc-in request [:headers "Authorization"] (str "Bearer 890")))
   :deflate (fn [response] (dissoc response :headers))})
Performs a `sync-request` with an encoded body and inflated context. The returned `{:keys [status body headers] :as response}`
is deflated and with a decoded body.

Refer to [sync-request options](https://github.com/ForbesLindesay/sync-request/) for all available features of the
context map including `:timeout`, `:retry`, `:maxRetries`, `:qs`, and more.

opts map

`:encode` - A function that takes the body from the context and transforms it before performing the request. Defaults to `clj->json` for JSON requests

`:decode` - A function that takes the body of the response and decodes it before returning a result. Defaults to `json->clj` for JSON requests

`:inflate` - A function that takes the full context and transforms it before performing the request.

`:deflate` - A function that takes the full response and transforms it before returning a result.


  ```clojure
  (request
    POST
    {:body {:id "123"} :headers {"Accept" "application/json"}}
    {:encode (fn [request-body] (assoc request-body :token "456"))
     :decode (fn [response-body] (-> response-body json->clj (assoc :response-time (js/Date.))))
     :inflate (fn [request] (assoc-in request [:headers "Authorization"] (str "Bearer 890")))
     :deflate (fn [response] (dissoc response :headers))})
  ```
  
sourceraw docstring

set-sync-request!cljs

(set-sync-request! sync-request)

Sets sync-request to the Javascript sync-request function

Sets *sync-request* to the Javascript `sync-request` function
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close