ClojureScript wrapper around the JavaScript fetch API.
(require '[lambdaisland.fetch :as fetch])
(fetch/get "/foo.json")
#<promise
{:status 200
:headers {...}
:body #js {...}}>
(fetch/post "/foo.transit" {:query-params {:foo "123"}
:body {:hello "world"}})
#<promise
{:status 200
:headers {...}
:body #js {...}}>
EDN support is opt-in, since it can increase your build size, and is not
typically needed or wanted for a production setup. Require
lambdaisland.fetch.edn
to enable it.
*
= default
:content-type
: determines the encoding of the request body and the content type header on the request. :transit-json
, :json
, :edn
, :form-encoded
, :text
, :html
:accept
: determines the requested encoded that the server should return.
Decoding is based on the content-type header in the response. Same values as
:content-type
:body
: request body to be encoded. If supplied with a string it will be used as-is, otherwise it gets encoded based on :content-type
:mode
: :no-cors
, *:cors
, same-origin
:cache
: *:default
, :no-cache
, :reload
, :force-cache
, :only-if-cached
:credentials
: :include
, *:same-origin
, :omit
:redirect
: :manual
, *:follow
, :error
:referrer-policy
: :no-referrer
, *:client
:headers
: map from string to string, note that the server must supply
Access-Control-Allow-Headers
in a preflight response
:body
: Clojure data structure to be encoded based on the :content-type
fetch is part of a growing collection of quality Clojure libraries created and maintained by the fine folks at Gaiwan.
Pay it forward by becoming a backer on our Open Collective, so that we may continue to enjoy a thriving Clojure ecosystem.
You can find an overview of our projects at lambdaisland/open-source.
Everyone has a right to submit patches to fetch, and thus become a contributor.
Contributors MUST
*
**
Contributors SHOULD
If you submit a pull request that adheres to these rules, then it will almost certainly be merged immediately. However some things may require more consideration. If you add new dependencies, or significantly increase the API surface, then we need to decide if these changes are in line with the project's goals. In this case you can start by writing a pitch, and collecting feedback on it.
*
This goes for features too, a feature needs to solve a problem. State the problem it solves, then supply a minimal solution.
**
As long as this project has not seen a public release (i.e. is not on Clojars)
we may still consider making breaking changes, if there is consensus that the
changes are justified.
Copyright © 2020-2021 Arne Brasseur and Contributors
Licensed under the term of the Mozilla Public License 2.0, see LICENSE.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close