Stream: show and tell

Topic: Roc CGI with roc-pg


view this post on Zulip Luke Boswell (May 28 2023 at 11:02):

I would like to share an experiment from today, roc-cgi-server. I haven't spent much time on it yet, but sharing in case someone has any ideas or feedback.

I've been wanting to check out @Agus Zubiaga roc-pg library, and also test out a vague idea I've been thinking about to make a web server using roc and CGI.

Basically it's just a golang web server which routes requests to roc basic-cli scripts, passing relevant parameters as environment variables. If I keep going in this direction I imagine working towards rfc3875 or similar.

The scripts are compiled into executables when the server loads. Initially I had it running the scripts on each request, but that was much slower on macOS. After changing it to build when server loads using --optimize, it was awesome fast (like single digit micro-seconds fast). Unfortunately with roc-pg --optimize runs a bit too slow.

% bash run.sh
2023/05/28 20:44:22 INFO: Listening on port 8080
2023/05/28 20:44:30 GET /todo 354 ms
2023/05/28 20:44:32 GET /todo/one 324 ms
2023/05/28 20:44:33 GET /todo 28 ms
2023/05/28 20:44:36 GET /todo/one 31 ms
2023/05/28 20:44:38 GET /todo 31 ms
2023/05/28 20:44:39 GET /todo/one 38 ms
2023/05/28 20:44:42 GET /todo 27 ms

Screen-Shot-2023-05-28-at-20.58.38.png
Screen-Shot-2023-05-28-at-20.58.46.png

view this post on Zulip Luke Boswell (May 28 2023 at 11:06):

Here is a link to the TodoDetail.roc script which loads the Todo from DB and then renders the detail page html.

view this post on Zulip Agus Zubiaga (May 28 2023 at 14:26):

Ooh nice! I like the elm-style HTML rendering!

view this post on Zulip Agus Zubiaga (May 28 2023 at 14:30):

Just pushed a new Pg.Result.apply function so that you can decode using Record Builders

view this post on Zulip Hannes (May 30 2023 at 14:15):

Very cool (ab)use of environment variables :grinning_face_with_smiling_eyes:

view this post on Zulip Hannes (May 30 2023 at 14:19):

Speaking of the elm style Html module, I was meaning to ask you @Luke Boswell if you could make that a standalone library? I started writing a static site generator for my website a while ago and just copy-pasted the code into my repo for now. Or I could create the library if you'd prefer?

view this post on Zulip Richard Feldman (May 30 2023 at 14:32):

@Hannes I'd say go for it!

Also if I remember right, I think @Brian Carroll was the original author of that static site generator? I could be misremembering though!

view this post on Zulip Hannes (May 30 2023 at 15:30):

Cool, I wasn't sure who the author was or what the licence was because I've seen it in a few places now

view this post on Zulip Anton (May 30 2023 at 15:34):

Unless something is in crates/vendor, everything in roc-lang/roc is licensed under the UPLv1.0 license

view this post on Zulip Brian Carroll (May 30 2023 at 18:50):

Yes, I created the original version, then Luke built things with it and I think maybe added stuff to the platform.

view this post on Zulip Brian Carroll (May 30 2023 at 18:59):

I don't particularly feel like doing a lot of maintenance for it so I'm ok with someone else making a package out of it. It's open source after all.

view this post on Zulip Luke Boswell (May 30 2023 at 20:14):

@Hannes if you setup a package for this I'd be interested to see if you setup a github action to build a release or URL package.

view this post on Zulip Richard Feldman (May 30 2023 at 20:17):

I think @Anton already set one of those up for basic-cli, if I remember right!

view this post on Zulip Hannes (May 31 2023 at 01:17):

Packaged and URL'd, see this thread :)

view this post on Zulip Brian Carroll (May 31 2023 at 06:52):

Cool! I appreciate you mentioning me in the README :)

view this post on Zulip Hannes (May 31 2023 at 11:07):

No problem, it felt like the least I could do seeing as you wrote most of it :sweat_smile:


Last updated: Jul 06 2025 at 12:14 UTC