remove clutch, add rest client instead

This commit is contained in:
Pavol Noha 2017-05-09 20:33:50 +02:00
parent e234875d1b
commit efd55367e5
2 changed files with 36 additions and 18 deletions

View file

@ -14,9 +14,11 @@
[ring/ring-json "0.4.0"]
[bidi "2.0.16"]
[http-kit "2.2.0"]
[clj-jwt "0.0.12"]
[cljs-ajax "0.5.8"]
[cheshire "5.6.3"]
[com.ashafa/clutch "0.4.0"]
[digest "1.4.5"]
[com.cemerick/friend "0.2.3"]
[com.cognitect/transit-cljs "0.8.239"]]
:plugins [[lein-cljsbuild "1.1.4"]]
@ -48,7 +50,6 @@
:provides ["cljsjs.material-ui"]
:requires ["cljsjs.react" "cljsjs.react.dom"]}]
:externs ["libs/material-ui/material-ui.ext.js"]
;:tooling-config {:devtools/config {:features-to-install :all}}
:preloads [devtools.preload]
:asset-path "js/out"
:output-to "resources/public/js/main.js"

View file

@ -1,22 +1,39 @@
(ns swarmpit.couchdb.client
(:require [com.ashafa.clutch :as clutch]))
(:refer-clojure :exclude [get])
(:require [org.httpkit.client :as http]
[cheshire.core :refer [parse-string generate-string]]))
(defn open-connection []
(let [conn (doto
(clutch/couch "swarmpit")
(clutch/create!))]
conn))
(def ^:private base-domain "localhost")
(def ^:private base-port 5984)
(def ^:private base-url
(str "http://" base-domain ":" base-port))
(def db-connection (delay (open-connection)))
(def headers
{"Accept" "application/json"
"Content-Type" "application/json"
"Host" "localhost:5984"})
(defn db [] @db-connection)
(defn execute
[call-fx]
(let [{:keys [body error]} call-fx]
(if error
(throw (ex-info "Failed connect to clutchdb!" {:error error}))
(parse-string body true))))
(defn load-record
[id]
{:body (get-in (db) [id])})
(defn get
[api]
(let [options {:headers headers}]
(execute @(http/get api options))))
(defn save-record
[data]
(let [id (get-in data ["_id"])]
(clutch/assoc! (db) id data)
{:body (get-in (db) [id])}))
(defn put
[api]
(let [url (str base-url api)
options {:headers headers}]
(execute @(http/put url options))))
(defn post
[api request]
(let [url (str base-url api)
options {:headers headers
:body (generate-string request)}]
(execute @(http/post url options))))