Skip to content

Instantly share code, notes, and snippets.

@jaen
Created February 8, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaen/7414aebdebf43af8f80a to your computer and use it in GitHub Desktop.
Save jaen/7414aebdebf43af8f80a to your computer and use it in GitHub Desktop.
(ns filemporium.client.api.common)
(:require-macros [cljs.core.match.macros :refer [match]])
(:require [ajax.core :as ajax]
[cljs.core.match]
[thattransit.handler.namespace :as transit-utils]))
(def my-default-formats
[#(ajax/transit-response-format {:handlers transit-utils/transit-read-handlers})])
(defn api-call [method uri opts]
(let [format {:format (ajax/transit-request-format {:handlers transit-utils/transit-write-handlers})
:response-format (ajax/detect-response-format {:response-format my-default-formats})}
api-opts (merge opts format)]
(match method
:get (ajax/GET uri api-opts)
:post (ajax/POST uri api-opts))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment