-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
jvm.clj
57 lines (49 loc) · 1.63 KB
/
jvm.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(ns portal.client.jvm
(:require [org.httpkit.client :as http]
[portal.runtime]
[portal.runtime.cson :as cson]
[portal.runtime.json :as json]
[portal.runtime.transit :as transit]))
(defn submit
"Tap target function.
Will submit values to a remote portal. Tapped value must be serialiable with
the encoding method provided.
Usage:
```clojure
(def submit (partial p/submit {:port 5678})) ;; :encoding :edn is the default
;; (def submit (partial p/submit {:port 5678 :encoding :json}))
;; (def submit (partial p/submit {:port 5678 :encoding :transit}))
(add-tap #'submit)
(remove-tap #'submit)
```
"
{:added "0.18.0" :see-also ["portal.api/submit"]}
([value] (submit nil value))
([{:keys [encoding port host]
:or {encoding :edn
host "localhost"
port 53755}}
value]
@(http/post
(str "http://" host ":" port "/submit")
{:headers
{"content-type"
(case encoding
:json "application/json"
:cson "application/cson"
:transit "application/transit+json"
:edn "application/edn")}
:body
(case encoding
:json (json/write value)
:transit (transit/write value)
:cson (cson/write value)
:edn (binding [*print-meta* true]
(pr-str value)))})))
(comment
(submit {:runtime :jvm :value "hello jvm"})
(submit {:port 1664} {:runtime :jvm :value "hello jvm"})
(add-tap submit)
(tap> {:runtime :jvm :value "hello jvm"})
(add-tap (partial submit {:encoding :json}))
(add-tap (partial submit {:encoding :transit})))