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
Here is a link to the TodoDetail.roc script which loads the Todo from DB and then renders the detail page html.
Ooh nice! I like the elm-style HTML rendering!
Just pushed a new Pg.Result.apply
function so that you can decode using Record Builders
Very cool (ab)use of environment variables :grinning_face_with_smiling_eyes:
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?
@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!
Cool, I wasn't sure who the author was or what the licence was because I've seen it in a few places now
Unless something is in crates/vendor, everything in roc-lang/roc is licensed under the UPLv1.0 license
Yes, I created the original version, then Luke built things with it and I think maybe added stuff to the platform.
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.
@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.
I think @Anton already set one of those up for basic-cli, if I remember right!
Packaged and URL'd, see this thread :)
Cool! I appreciate you mentioning me in the README :)
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