ring

Ken Huang 2024-12-28T02:38:33.562259Z

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?

Ken Huang 2024-12-28T02:43:25.505089Z

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

Ken Huang 2024-12-28T03:28:48.675069Z

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

seancorfield 2024-12-28T03:55:20.746779Z

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
seancorfield 2024-12-28T03:58:01.649149Z

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.

Ken Huang 2024-12-28T04:01:54.582229Z

Got it, thanks for the explanations!

seancorfield 2024-12-28T04:07:00.401499Z

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

Ken Huang 2024-12-28T04:08:41.734329Z

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.

Ken Huang 2024-12-28T04:11:32.902169Z

Thanks, I'll look into usermanager later.