(error-routine* get-response ok-routine progress-routine raw-error-handler)
Returns a (fn [xhrio-evt]) that pulls the progress and reports it to the progress routine and the raw error handler.
Returns a (fn [xhrio-evt]) that pulls the progress and reports it to the progress routine and the raw error handler.
(extract-response tx request xhrio)
Generate a response map from the status of the given xhrio object, which could be in a complete or error state.
Generate a response map from the status of the given xhrio object, which could be in a complete or error state.
(fulcro-http-remote {:keys [url request-middleware response-middleware]
:or {url "/api"
response-middleware (wrap-fulcro-response)
request-middleware (wrap-fulcro-request)}
:as options})
Create a remote that (by default) communicates with the given url (which defaults to /api
).
The request middleware is a (fn [request] modified-request)
. The request
will have :url
, :body
, :method
, and :headers
. The
request middleware defaults to wrap-fulcro-request
(which encodes the request in transit+json). The result of this
middleware chain on the outgoing request becomes the real outgoing request. It is allowed to modify the url
.
If the the request middleware returns a corrupt request or throws an exception then the remote code
will immediately abort the request. The return value of the middleware will be used to generate a request to :url
,
with :method
(e.g. :post), and the given headers. The body will be sent as-is without further translation.
response-middleware
is a function that returns a function (fn [response] mod-response)
and
defaults to wrap-fulcro-response
which decodes the raw response and transforms it back to a response that Fulcro can merge.
The response will be a map containing the :transaction
, which is the
original Fulcro EDN request; :outgoing-request
which is the exact request sent on the network; :body
, which
is the raw data of the response. Additionally, there will be one or more of the following to indicate low-level
details of the result: :status-code
, :status-text
, :error-code
(one of :none, :exception, :http-error, :abort, or :timeout),
and :error-text
. Middleware is allowed to morph any of this to suit its needs.
A result with a 200 status code will result in a merge using the resulting response's :transaction
as the query,
and the :body
as the EDN to merge. If the status code is anything else then the details of the response will be
used when triggering the built-in error handling (e.g. fallbacks, global error handler, etc.).
Create a remote that (by default) communicates with the given url (which defaults to `/api`). The request middleware is a `(fn [request] modified-request)`. The `request` will have `:url`, `:body`, `:method`, and `:headers`. The request middleware defaults to `wrap-fulcro-request` (which encodes the request in transit+json). The result of this middleware chain on the outgoing request becomes the real outgoing request. It is allowed to modify the `url`. If the the request middleware returns a corrupt request or throws an exception then the remote code will immediately abort the request. The return value of the middleware will be used to generate a request to `:url`, with `:method` (e.g. :post), and the given headers. The body will be sent as-is without further translation. `response-middleware` is a function that returns a function `(fn [response] mod-response)` and defaults to `wrap-fulcro-response` which decodes the raw response and transforms it back to a response that Fulcro can merge. The response will be a map containing the `:transaction`, which is the original Fulcro EDN request; `:outgoing-request` which is the exact request sent on the network; `:body`, which is the raw data of the response. Additionally, there will be one or more of the following to indicate low-level details of the result: `:status-code`, `:status-text`, `:error-code` (one of :none, :exception, :http-error, :abort, or :timeout), and `:error-text`. Middleware is allowed to morph any of this to suit its needs. A result with a 200 status code will result in a merge using the resulting response's `:transaction` as the query, and the `:body` as the EDN to merge. If the status code is anything else then the details of the response will be used when triggering the built-in error handling (e.g. fallbacks, global error handler, etc.).
(ok-routine* progress-routine get-response-fn raw-ok-handler error-routine)
Returns a (fn [evt] ) that pulls the response, runs it through middleware, and reports the appropriate results to the raw-ok-handler, and progress-routine. If the middleware fails, it will instaed report to the error-routine (which in turn will report to the raw error handler)
Returns a (fn [evt] ) that pulls the response, runs it through middleware, and reports the appropriate results to the raw-ok-handler, and progress-routine. If the middleware fails, it will instaed report to the error-routine (which in turn will report to the raw error handler)
(progress% progress)
(progress% progress phase)
Takes the progress report from the progress network event
and returns a number between 0 and 100. phase
can be :overall
, :sending
, or :receiving
. When
set to :overall
then the send phase will count for progress points between 0 and 49, and receiving phase
will account for 50 to 100. When set to :sending or :receiving the entire range will count for that phase only
(i.e. once sending is complete this function would return 100 throughout the receiving phase.)
If total is unknown, then this function returns 0.
Takes the progress report from the progress network event and returns a number between 0 and 100. `phase` can be `:overall`, `:sending`, or `:receiving`. When set to `:overall` then the send phase will count for progress points between 0 and 49, and receiving phase will account for 50 to 100. When set to :sending or :receiving the entire range will count for that phase only (i.e. once sending is complete this function would return 100 throughout the receiving phase.) If total is unknown, then this function returns 0.
(progress-routine* get-response-fn raw-update-fn)
Return a (fn [phase progress-event]) that calls the raw update function with progress and response data merged together as a response.
Return a (fn [phase progress-event]) that calls the raw update function with progress and response data merged together as a response.
(was-network-error? {:keys [status-code error]})
Returns true if the given response looks like a low-level network error.
Returns true if the given response looks like a low-level network error.
(wrap-csrf-token csrf-token)
(wrap-csrf-token handler csrf-token)
Client remote request middleware. This middleware can be added to add an X-CSRF-Token header to the request.
Client remote request middleware. This middleware can be added to add an X-CSRF-Token header to the request.
(wrap-fulcro-request)
(wrap-fulcro-request handler)
(wrap-fulcro-request handler addl-transit-handlers)
(wrap-fulcro-request handler addl-transit-handlers transit-transformation)
Client Remote Middleware to add transit encoding for normal Fulcro requests. Sets the content type and transforms an EDN
body to a transit+json encoded body. addl-transit-handlers is a map from data type to transit handler (like
you would pass using the :handlers
option of transit). The additional handlers are used to encode new data types
into transit. transit-transformation is a function of one argument returning a transformed transit value (like you
would pass using the :transform
option of transit). See transit documentation for more details.
Client Remote Middleware to add transit encoding for normal Fulcro requests. Sets the content type and transforms an EDN body to a transit+json encoded body. addl-transit-handlers is a map from data type to transit handler (like you would pass using the `:handlers` option of transit). The additional handlers are used to encode new data types into transit. transit-transformation is a function of one argument returning a transformed transit value (like you would pass using the `:transform` option of transit). See transit documentation for more details.
(wrap-fulcro-response)
(wrap-fulcro-response handler)
(wrap-fulcro-response handler addl-transit-handlers)
Client remote middleware to transform a network response to a standard Fulcro form.
This returns a function that will decode a transit response iff the resulting status code is 200 and the body is not empty. For errant status codes and empty body: the response body will become an empty map.
No arguments: Returns a function that can process responses, that is not further chained.
handler: If supplied, the result of this transformation will be passed through the handler
.
addl-transit-handlers is equivalent to the :handlers option in transit: a map from data type to handler.
Client remote middleware to transform a network response to a standard Fulcro form. This returns a function that will decode a transit response iff the resulting status code is 200 and the body is not empty. For errant status codes and empty body: the response body will become an empty map. No arguments: Returns a function that can process responses, that is not further chained. handler: If supplied, the result of this transformation will be passed through the `handler`. addl-transit-handlers is equivalent to the :handlers option in transit: a map from data type to handler.
(xhrio-progress event)
Given an xhrio progress event, returns a map with keys :loaded and :total, where loaded is the number of bytes transferred in the given phase (upload/download) and total is the total number of bytes to transfer (if known).
Given an xhrio progress event, returns a map with keys :loaded and :total, where loaded is the number of bytes transferred in the given phase (upload/download) and total is the total number of bytes to transfer (if known).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close