Fork me on GitHub
#clojurescript
<
2020-02-21
>
jeroenvandijk08:02:29

What's a good clojurescript library to handle a SSE response (Server-Sent Events) [editted]? I found some old libs (chord) and the main one cljs-http doesn't seem to handle the body in an async way

littleli08:02:14

technically it's Server-Sent Events

littleli08:02:09

it should be just a regular http request that is reading from the connection until it's closed, and after that it starts again.

jeroenvandijk09:02:52

a yeah typed too quickly lol. I know it's very "simple", with curl for instance. But cljs-http doesn't allow me to do it (I think). Do you have a specific library or everything hand-rolled?

Crispin09:02:00

I use websockets for this type of server push.

jeroenvandijk09:02:56

@U1QQJJK89 Any specific library to use with websockets (client side)?

jeroenvandijk09:02:46

I feel we have a gap for a proper http library. Especially one that has one interface over all the different platforms that clojure now is targetting

Crispin09:02:48

Nothing client side. Im using immutant server side. Then just js interop client side. some core.async. transit encoding with LZString compression.

Crispin09:02:06

multimethods for message routing on top of the websockets

Crispin09:02:52

what I have found amazing is websockets + transit + multimethods + cljc as a gamechanger (IMHO). Being able to write client/server messaging "workflows" in a single cljc file with automatic dispatch (via multimehtods) feels pretty liberating.

jeroenvandijk09:02:26

Yeah exactly, I want that too. And the core of clojure works great on several platforms. It's the edges where you find yourself lost. E.g. now I want to do http requests. I have something for this that works on the server side, but when I think hey let's do this in a GraalVM environment or nodejs, or browser, they will all have a different implementation. If we can fix that .. 🙂

pithyless09:02:24

@U0FT7SRLP for websockets I recommend sente (handles client and server with reconnects and downgrades to ajax) - https://github.com/ptaoussanis/sente

👍 8
4
❤️ 4
jsa-aerial15:02:34

You should definitely take a look at Hanasu https://github.com/jsa-aerial/hanasu It is a lot simpler than Sente but is very flexible.

👍 4
👁️ 4
jeroenvandijk16:02:18

It seems most people are more into websockets

jsa-aerial16:02:21

Yes, generally I now use them for all this client/server (and/or peer to peer) communication. For the most part it is simpler, more flexible, and just works. For example, I use Hanasu extensively in several projects and I know some others do as well. I use it for python communication as well https://github.com/jsa-aerial/pyhanasu

sova-soars-the-sora02:02:46

Do you have an example clj/cljs/cljc project written in Hanasu one could examine?

jsa-aerial06:02:39

several. Aerobio (which also uses pyhansu), Hanami and Saite are the public available ones: https://github.com/jsa-aerial/aerobio, https://github.com/jsa-aerial/hanami, https://github.com/jsa-aerial/saite

jsa-aerial06:02:01

There are some others that I need/should release. These are not so much "written in Hanasu" as "written with Hanasu as the msg service"

jeroenvandijk09:03:06

I hope that a part of my issues with CLJS clients will be tackled by the new ring spec (see my point in this thread https://github.com/ring-clojure/ring/issues/393#issuecomment-593863601)

Frederik12:02:39

Where do beginners clojurescript questions belong? Because the following question will show I'm a total beginner in both clojurescript and web dev in general I'm afraid 😄. I trained a machine learning model in clojure and now I would like to use it in a small interactive webpage. I dived into using clojurescript for this, without really thinking much of exactly how I would communicate between my webapp and the model. The input for the model is a simple clojure vector, the output a single number. What would be the best way to this input-output communication going between clojurescript and clojure?

p-himik12:02:38

It's either here or in #beginners

p-himik12:02:04

As to your actual question, it seems like a plain AJAX request is more than enough.

Frederik12:02:39

Thanks for the quick answer! 🙂 I'll look into AJAX requests, a quick search suggests to use cljs-http, is that still the standard/easiest way?

p-himik12:02:16

Yeah, the library is still widely used, you should be fine with it.

Frederik12:02:32

Great thanks! A last, very beginner question, is it ok to use the same base url (with different routing ofc) for both my clojurescript app and for my clojure "api"?

Robin Jakobsson13:02:34

Yes, that should work.

matheusashton20:02:17

I’m trying to make a router work with an re-frame application, but I’m not sure yet how do I make something like react-router with clojurescript, anyone that can help with? I tried to use secretary and now I’ve changed to re-frame-routing that uses bidi and pushy under the hood, but I still couldn’t make it work

p-himik20:02:51

I'm using kee-frame with bidi, it works perfectly. What do you mean by "couldn't make it work", what were the exact issues?

Crispin02:02:06

I have used secretary without problems. What does react-router do differently?

matheusashton16:02:17

The problem is that I couldn’t sync secretary’s dispatch! with browser’s url, I was able to route the application internally but the route doesn’t reflect on the browser URL, and if I try to change the URL manually (like a href’s link) the page reloads

schaueho16:02:16

I've recently had the same question for secretary. Take a look at accountant which works together with secretary to take care of the browser history, it will update the browser, too.