Fork me on GitHub

Hi, I have a clojurescript app with clojure backend and now I am trying to send some static data (config) from the backend to the frontend on page load. I was thinking to send it as a JSON structure that the clojurescript app picks up. 1. Is there a better way? 2. If this is the best way, how do i convert a clojure map to a JSON map?


If you're the only client of that config (no third parties), then Transit ( would be most efficient. But if you want to use JSON without Transit, then clj->js then calling (js/JSON.stringify (clj->js {:a 5})) would be the way


excellent answer! Thanks @troglotit


but how can i convert to JSON on the backend_ clj->js seem to only work in clojurescript?

ūüėÖ 1
curlyfry11:04:00 is a popular library for handling json in Clojure

‚ěē 1

@karl.jakob.lind Another approach if the data is truly static is to keep it in a .cljc file that can be used both from Clojure and ClojureScript


:thumbsup: thanks!


I have a constants.cljc with some maps, works great.


Hi, when having two luminus projects running with lein run should one change the default port nr. 7000 for one of them? I'm asking this because tried to find the name of processes with lsof -i but couldn't find any in that port.


Is there anyone tried to build an app with Reagent/Rum/etc with Apollo? Maybe there are blogposts or tutorials


I used re-graph, to connect to a GraphQL endpoint. It's a nice small library that works well.

Karol Wójcik18:04:14

Hello I am trying to wrap my head around ring routing and the role of compojure in making the ring handlers. After some investigation, I found that the ring accepts the handler in which we have to explicitly match the route. The role of compojure is then to create a handler which on request calls (handler request) and if the route matches then it's called. Otherwise the nil is returned and other handlers for the route are called. I am very curious if I am right. If so then I would highly appreciate if you could explain to me why the ring is implemented in fashion when to match the route every single handler is taken into account. Wouldn't be better to have some sort of map which when the request occurs then matches to correct handler?


@kwcharllie379 Ring itself has no concept of routing. It defines a simple abstraction over HTTP request & response - requests are maps with certain keys, and responses are maps with certain keys. A ring handler is a function that takes a request and returns a response. Compojure adds a layer of routing on top of this, as well as a number of syntactic and developer convenience features. When you use compojure’s routes function or defroutes macro, the result is a ring handler.

Karol Wójcik18:04:02

@michael.gaare Yes I understand it very well I think. But don't you think it's some kind of time consuming to go through all handlers in order to match the route?


@kwcharllie379 Well, that’s getting into the implementation details of how compojure handles routing. bidi is another routing library that uses a trie for this rather than compojure’s more linear approach

Karol Wójcik18:04:56

Yes this is what I tried to say it's linear approach.


Sorry, yes, linear on count routes defined


Which is likely a very small n

Karol Wójcik19:04:07

I do not think so. Simple route like "/users" has 4 handlers because of GET, POST, DELETE, PUT. So for evey route there are at least 1 to 4 handlers. Which in my opinion is not very optimal.


If that's a likely bottleneck, clojure won't perform well enough for the application


Also, linear search over a collection that small is faster than a hash lookup on real world cpus

Karol Wójcik19:04:13

Ooo really I didn't know that. Thank you very much for the clarification.

Karol Wójcik20:04:14

I really appreciate that.


btw, pedestal has 3 routers for you to choose from. Fast, faster & slow/flexible

Karol Wójcik18:04:06

Guide me please which path should I take? What do you prefer? I came from the Node.js world and I do not know which path should i take 1. Compojure and compojure-api 2. Pedestal


Pedestal also means not using ring, right?


Pedestal allows you to use ring, but it also has its own async middlewares thing that can be more performant if you target that

Karol Wójcik18:04:57

So pedestal is right choice, right?

Karol Wójcik18:04:16

Ring is some kind of express as I can see


Personally I’d go with compojure & compojure-api. Coming from node.js, it has this nice swagger UI built in

Karol Wójcik19:04:41

Ok maybe it's the right path, because I can find a lot of similarities between Node.js and Ring & Compojure and since I am beginner it would be better to explore the Clojure in the area in which I am comfortable. Thank you @michael.gaare @rauh @noisesmith


how do i use clojure.spec to validate the existence of a file? should i be doing that?


i'm reading in an edn file as a config file and i'd like to validate the config