ring 2024-12-28

Hi, I'm playing around with ring, but I'm surprised that a handler can not return a hiccup list, so how do you do that? I didn't find something after search, maybe I should write a small middleware for it?

Ah, just returning string with hiccup2/html is also a way, but I don't like it very much.

Hmm, I should offload this to cljs and just use ring for APIs.

Just to note that Ring core does almost nothing -- just the request/response stuff -- and almost everything comes in via middleware. If you're only going to return Hiccup vectors, that seems like a perfect use for middleware.

❤️ 1

If you're doing a full cljs frontend, an SPA, then having the backend Ring app only serve JSON seems reasonable -- but that's also middleware, not core.

Got it, thanks for the explanations!

FWIW, I tend to use Selmer to produce HTML from templates, and I generally do that via middleware... The usermanager example app does this: https://github.com/seancorfield/usermanager-example/blob/develop/src/usermanager/main.clj#L70-L80 and https://github.com/seancorfield/usermanager-example/blob/develop/src/usermanager/controllers/user.clj#L13-L24

I'm not sure, I'm not familiar with SPA yet, so maybe I'll just do it in a mixed flavor: build cljs to static htmls/js, .etc. And then serve this static files from Ring. This is what I have in my mind currently.

Thanks, I'll look into usermanager later.