Liking cljdoc? Tell your friends :D

reacl-c-basics.ajax

This namespace contains utilities to do AJAX requests in a reacl-c application, based on cljs-ajax.

At a glance, you first define requests with GET, POST and PUT.

GET requests are usually there to get some data from a server and display it to the user. Typically you want to use fetch or a variant of it to do that, or the lower level execute. For example:

(c/fragment (fetch (GET "/resource"))
            (c/dynamic pr-str))

POST and PUT requests are typically sent in response to an action by the user. The delivery item and the deliver action are made to help with that:

(delivery
 (dom/button
  {:onclick #(c/return :action (deliver (PUT "/resource" {:body v})))}))

Note that all items cancel outstanding requests when they are removed from the dom tree.

For details on the various options of the request constructors, see the documentation of cljs-ajax.

Also see reacl-c-basics.ajax-test-util for an easy way to simulate server responses in unit tests.

This namespace contains utilities to do AJAX requests in a reacl-c application, based on `cljs-ajax`.

At a glance, you first define requests with [[GET]], [[POST]]
and [[PUT]].

GET requests are usually there to get some data from a server and
display it to the user. Typically you want to use [[fetch]] or a
variant of it to do that, or the lower level [[execute]]. For
example:

```
(c/fragment (fetch (GET "/resource"))
            (c/dynamic pr-str))
```

POST and PUT requests are typically sent in response to an action by
the user. The [[delivery]] item and the [[deliver]] action are made
to help with that:

```
(delivery
 (dom/button
  {:onclick #(c/return :action (deliver (PUT "/resource" {:body v})))}))
```

Note that all items cancel outstanding requests when they are
removed from the dom tree.

For details on the various options of the request constructors, see
the documentation
of [`cljs-ajax`](https://github.com/JulianBirch/cljs-ajax#getpostput).

Also see [[reacl-c-basics.ajax-test-util]] for an easy way to
simulate server responses in unit tests.
raw docstring

DELETEcljs

(DELETE uri & [options])

Returns a DELETE request.

Returns a DELETE request.
sourceraw docstring

delivercljs

(deliver req & [info])

Returns an action to add the given request to the end of the next delivery up in the item tree. An arbitrary info value can be attached, identifying or describing the request.

Returns an action to add the given request to the end of the next
[[delivery]] up in the item tree. An arbitrary `info` value can be
attached, identifying or describing the request.
sourceraw docstring

deliverycljs

(delivery item)
(delivery item options)
(delivery item transition manage)

Returns an item that manages the execution of Ajax requests in its local state. Use deliver to get an action that can be emitted by item that adds a new delivery job to an internal queue.

:transition option: Jobs transition from a :pending state, over :running into :completed (successful or not), and for each transition (transition state job) is evaluated on the returned item's state, which must return a [[reacl-c.core/return]] value.

:manage option: Some control over the queue can be achieved by specifying manage which is called on the queue after it changed and must return an updated queue. You can remove jobs or change their order for example. Newest items are at the end of the queue.

:execute option: The item function to actually execute the requests can also be explicitly set; it defaults to execute.

Note: (delivery item transition manage) is deprecated.

Returns an item that manages the execution of Ajax requests in its
local state. Use [[deliver]] to get an action that can be emitted by
`item` that adds a new delivery job to an internal queue.

`:transition` option:
Jobs transition from a :pending state,
over :running into :completed (successful or not), and for each
transition `(transition state job)` is evaluated on the returned
item's state, which must return a [[reacl-c.core/return]] value.

`:manage` option:
Some control over the queue can be achieved by
specifying `manage` which is called on the queue after it changed
and must return an updated queue. You can remove jobs or change
their order for example. Newest items are at the end of the queue.

`:execute` option:
The item function to actually execute the requests can also be
explicitly set; it defaults to [[execute]].

Note: `(delivery item transition manage)` is deprecated.
sourceraw docstring

delivery-job-infocljs

(delivery-job-info job)

Returns the info object passed to deliver.

Returns the info object passed to [[deliver]].
sourceraw docstring

delivery-job-responsecljs

(delivery-job-response job)

Returns the response for this job, or nil if the status is not :completed.

Returns the response for this job, or nil if the status is not `:completed`.
sourceraw docstring

delivery-job-statuscljs

(delivery-job-status job)

Returns the status of this job, :pending, :running or :completed.

Returns the status of this job, `:pending`, `:running` or `:completed`.
sourceraw docstring

delivery-job?cljs

(delivery-job? v)
source

error-responsecljs

(error-response status & [body])

Returns a response that is considered a failure, with a map with :status and :body keys as its response-value.

Returns a response that is considered a failure, with a map with `:status` and `:body` keys as its [[response-value]].
sourceraw docstring

executecljs

(execute request)

A subscription that will execute the given request and deliver the response as soon as it is available.

A subscription that will execute the
given request and deliver the response as soon as it is available.
sourceraw docstring

execute!cljs

(execute! request)

An effect that will execute the given request. If you want access to the response, use execute.

An effect that will execute the given
request. If you want access to the response, use [[execute]].
sourceraw docstring

fetchcljs

(fetch req)

Returns an invisible item, that will execute the given request whenever its state is or becomes nil, and set its state to the success or error response as soon as it is available.

Returns an invisible item, that will
execute the given request whenever its state is or becomes nil, and
set its state to the success or error response as soon as it is
available.
sourceraw docstring

fetch-oncecljs

(fetch-once req f)

Returns an invisible item, that will execute the given Ajax request once, when mounted. When the request completes with an error or success, then (f state response) is evaluated, which must return a [[reacl-c.core/return]] value.

Returns an invisible item, that will execute the given Ajax
request once, when mounted. When the request completes with an error
or success, then `(f state response)` is evaluated, which must
return a [[reacl-c.core/return]] value.
sourceraw docstring

fetch-whencljs

(fetch-when req cond)

Returns an invisible item, that will execute the given request once if cond is true, and also whenever cond changes from false to true. Updates its state to the response after each request completed (successful or not).

Returns an invisible item, that will execute the given request once
if `cond` is true, and also whenever `cond` changes from false to
true. Updates its state to the response after each request
completed (successful or not).
sourceraw docstring

fetch-when+statecljs

(fetch-when+state req cond)

Returns an invisible item, that will execute the given request once if cond is true, and also whenever cond changes from false to true. Updates its state to a tuple of the response and a loading flag:

  • true when a request is started, but hasn't completed yet
  • false when a request is completed.

Initialize the state to false or nil.

Returns an invisible item, that will execute the given request once
if `cond` is true, and also whenever `cond` changes from false to
true. Updates its state to a tuple of the response and a loading flag:

- `true` when a request is started, but hasn't completed yet
- `false` when a request is completed.

Initialize the state to false or nil.
sourceraw docstring

GETcljs

(GET uri & [options])

Returns a GET request.

Returns a GET request.
sourceraw docstring

(HEAD uri & [options])

Returns a HEAD request.

Returns a HEAD request.
sourceraw docstring

map-ok-responsecljs

(map-ok-response req f & args)

Convert the response-value of every successfull responses to the given request through a call to (f response & args).

Convert the [[response-value]] of every successfull responses to the given request through a
call to `(f response & args)`.
sourceraw docstring

map-responsecljs

(map-response req f & args)

Convert every response to the given request through a call to (f response & args).

Convert every response to the given request through a call to `(f response & args)`.
sourceraw docstring

ok-responsecljs

(ok-response result)

Returns a response that is considered a success with the given value as its response-value.

Returns a response that is considered a success with the given value as its [[response-value]].
sourceraw docstring

OPTIONScljs

(OPTIONS uri & [options])

Returns a OPTIONS request.

Returns a OPTIONS request.
sourceraw docstring

PATCHcljs

(PATCH uri & [options])

Returns a PATCH request.

Returns a PATCH request.
sourceraw docstring

POSTcljs

(POST uri & [options])

Returns a POST request.

Returns a POST request.
sourceraw docstring

PURGEcljs

(PURGE uri & [options])

Returns a PURGE request.

Returns a PURGE request.
sourceraw docstring

PUTcljs

(PUT uri & [options])

Returns a PUT request.

Returns a PUT request.
sourceraw docstring

request?cljs

(request? value)

Returns whether the given value is a request.

Returns whether the given value is a request.
sourceraw docstring

response-ok?cljs

(response-ok? response)

Returns if the given response represents success, i.e. the status code was in the 2xx range.

Returns if the given response represents success, i.e. the status code was in the 2xx range.
sourceraw docstring

response-valuecljs

(response-value response)

Returns the (parsed) response body of the given response if ok, or a map with :status and :body keys if not ok.

Returns the (parsed) response body of the given response if ok, or a map with `:status` and `:body` keys if not ok.
sourceraw docstring

response?cljs

(response? value)

Returns whether the given value is a response.

Returns whether the given value is a response.
sourceraw docstring

TRACEcljs

(TRACE uri & [options])

Returns a TRACE request.

Returns a TRACE request.
sourceraw docstring

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

× close