This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-27
Channels
- # beginners (54)
- # bitcoin (2)
- # boot (1)
- # calva (10)
- # cider (30)
- # cljs-dev (25)
- # cljsrn (17)
- # clojure (27)
- # clojure-dev (16)
- # clojure-estonia (3)
- # clojure-hk (1)
- # clojure-italy (8)
- # clojure-losangeles (1)
- # clojure-nl (17)
- # clojure-russia (1)
- # clojure-spec (15)
- # clojure-uk (45)
- # clojurebridge (1)
- # clojurescript (95)
- # clojurescript-ios (1)
- # core-async (5)
- # cursive (10)
- # datomic (8)
- # emacs (2)
- # figwheel-main (31)
- # fulcro (99)
- # hyperfiddle (3)
- # immutant (1)
- # jobs (13)
- # jobs-discuss (82)
- # keechma (6)
- # leiningen (3)
- # lumo (1)
- # nrepl (1)
- # off-topic (37)
- # onyx (1)
- # pedestal (6)
- # re-frame (7)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (3)
- # rum (6)
- # shadow-cljs (14)
- # specter (4)
- # tools-deps (27)
- # yada (12)
Anyone got an example on how to integrate yada and sente? I’ve looked at SSE but we need to support IE/Edge. I got:
:get
{:parameters {:query {:handshake? s/Bool
:udt String
:client-id String
s/Any s/Any}}
:response (fn [ctx]
(let [query (get-in ctx [:parameters :query])
req (update (:request ctx) :params merge query)
sente-response (ring-ajax-get-or-ws-handshake req)]
(:body sente-response)))}
but this is obviously not working.I’ve had trouble to make it work with yada and polling etc., although it works fine with sente websockets transport. (on a personal project though so I never had much time to dig around)
You’re not the first to ask in this channel though - I did the same quite some time ago. It took some trial and error and I have this at the moment:
(defn- ringify [ctx]
(update ctx :request (comp
ring.middleware.keyword-params/keyword-params-request
ring.middleware.params/params-request)))
(defn- handlers [{:keys [ajax-post-fn
ajax-get-or-ws-handshake-fn]}]
{::chsk (yada/resource {:description "Sente endpoints"
:consumes yada.util/consumes
:produces yada.util/produces
:methods {:get {:response (fn [ctx]
(def ctx ctx)
(let [req (:request (ringify ctx))
res (:response ctx)]
(let [result (ajax-get-or-ws-handshake-fn req)]
;; TODO assoc ctx
;; + look at headers etc.
;; for websockets
;; TODO see for Ajax too
(def result result)
(type result)
(println "NOT RETURNGING BODY - TODO AJAX" (:body result))
(assoc res :body (:body (deref result)))
;; com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class manifold.stream.SplicedStream: manifold.stream.SplicedStream@42d74aea
;; originalMessage: "Cannot JSON encode object of class: class manifold.stream.SplicedStream: manifold.stream.SplicedStream@42d74aea"
nil)))}
:post {:response (fn [ctx]
(let [req (ringify ctx)]
(assoc ctx :body (ajax-post-fn req))))}}})} )
note you have to use the sente aleph adapter too (not shown above).
My code looks a bit weird (still lots of debugging stuff left in there) - I would be very interested in seeing what you come up with @borkdude 😄I have the same exception: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class manifold.stream.SplicedStream:
cool, I’ll try that maybe. I don’t reeeally need SSE/websockets, but it would be nice to have
The odd thing is that it worked for me with bidi + compojure instead of yada for a resource handler. It did feel very clunky though (I don’t think I have sample code handy anymore though I will be able to dig a bit this weekend).
This and https://github.com/juxt/yada/issues/205 are basically the two things I miss from Yada (the issue is because I would love to reuse my existing Yada API for my websocket messages - without making an actual request to myself 🤪)