ClojureScript + HTTP + Promises
We have two other libraries for HTTP requests on cljs, why do we need another one?
Neither of the existing libraries support promises. One uses callbacks and the other core.async
.
Personally I find promises simpler and fit the model of functional programming better. Out of the box the other two libraries will do far more for you, they'll set content types, accept types and parse the responses for you. Here you'll get none of that. This library aims to do one thing and one thing well - HTTP requests, nothing more.
The request object passed to this library should take the form of the Ring request map. Requests will immediately return a promise that will eventually be resolved to contain a Ring response map. The implementation of promises used comes from Promesa. Non-sucessful HTTP requests will be rejected but the value contained in the promise will still be a Ring response map. Success is defined by the isSuccess()
method on the XhrIo response
TODO
# Start a repl
clj --main cljs.main --compile ajax-promises.main --repl
# Start a repl with node.js
# Don't use this as node doesn't have XMLHttpRequest
clj --main cljs.main --compile ajax-promises.main --repl --repl-env node
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close