This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-12
Channels
- # admin-announcements (3)
- # beginners (13)
- # boot (52)
- # cbus (1)
- # cider (13)
- # cljs-dev (70)
- # cljsjs (16)
- # cljsrn (124)
- # clojure (129)
- # clojure-austin (3)
- # clojure-boston (2)
- # clojure-russia (238)
- # clojure-sg (3)
- # clojurescript (119)
- # cursive (18)
- # datomic (22)
- # editors-rus (2)
- # events (1)
- # hoplon (160)
- # jobs (1)
- # jobs-rus (8)
- # ldnclj (31)
- # ldnproclodo (1)
- # lein-figwheel (4)
- # leiningen (8)
- # off-topic (3)
- # om (335)
- # onyx (29)
- # re-frame (15)
- # reagent (12)
- # robots (1)
- # yada (19)
Hello, does yada support transit requests ? Also, is there an example of a yada component somewhere ?
Ok the component was straightforward. As for the transit requests, I'm not there yet. Also out of curiosity I see in the bidi
readme that liberator is supported, is it also possible with yada ? If yes, how easy would it be ?
transit requests? you mean transit encoded data a request body?
(or response of the appropriate header is set - I mean can the data be exchanged in transit format? )
Also, I am trying to sent SSE in a response :
;; from aleph example
(defn stream-example
[{:keys [params] :as ctx}]
(let [cnt (Integer/parseInt (get params "count" "0"))]
{:status 200
:headers {"content-type" "text/plain"}
:body (let [sent (atom 0)]
(->> (s/periodically 100 #(str (swap! sent inc) "\n"))
(s/transform (take cnt))))}))
;; another test
(defn stream-example [req]
(yada
:allow-origin true
:body {"text/event-stream"
(fn [_]
(let [ch (chan 256)]
(go
(>! ch "It works!"))
ch))}))
(def api-routes
["" [["/hello-api"
(yada/swaggered
{:info {:title "Hello World!"
:version "1.0"
:description "Demonstrating yada + swagger"}
:basePath "/hello-api"}
["/hello" hello])]
["/chat"
(yada/swaggered
{:info {:title "Chat service"
:version "1.0"
:description "test"}
:basePath "/chat"}
["/stream-example" stream-example])]
[true (fn [req] {:status 404 :body "Nada!"})]]])
(two different tries). does someone spot what is wrong ?@nha: I haven't tried it yet, but this exists: https://github.com/juxt/yada/blob/master/src/yada/resources/sse.clj
it requires you to use a core async channel though, but if you like to work with manifold streams you could replace the mult with a manifold event-bus I think
(defn state-event-stream [event-bus cron _]
{:headers {"content-type" "text/event-stream"}
:body (stream/transform (map (partial format "data: %s\n\n"))
(stream/->source (state cron event-bus)))})
And state returns a core.async channel
but stream/->source also accepts manifold streams
@nha: Maybe this helps?
@nha sorry I just copy pasted something from a project where we use this.
@nha your :body
should return this: (transform (map (partial format "data: %s\n\n")) (->source ch))
where ch
is your channel.
See the example from @stijn