Skip to content

Instantly share code, notes, and snippets.

@alwx
Created June 24, 2016 10:20
Show Gist options
  • Save alwx/6a5050bf17140307f4b8f9d9700a5d84 to your computer and use it in GitHub Desktop.
Save alwx/6a5050bf17140307f4b8f9d9700a5d84 to your computer and use it in GitHub Desktop.
(def transit-reader (t/reader :json))
(-> (js/fetch api-url
(clj->js {:headers {"Accept" "application/transit+json"}}))
(.then (fn [response]
(.text response)))
(.then (fn [response]
(let [data (t/read transit-reader response)]
;; we're done
;; `data` is a clojurescript map
;; and we're able to use this map any way we want
(dispatch [:api-method-call-success data]))))
(.catch (fn [error]
(dispatch [:api-method-call-error error]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment