Small web apps in Lisp on cheap hosting: Cljs + Transit + (Hy or Phel)

A recent blog post, Clojure like its PHP, shows that Clojure can serve requests as a cgi-bin script running through Babashka.

Wanting to try this out myself, I had to learn that the local webhost providers I checked did not allow to run executables.

But some allow running Python cgi scripts. So I went on and tried Hy, a Clojure inspired Lisp that compiles to Python’s AST.

I implemented a small backend for the Lumninus guestbook example written in Cljs/Reagent. You can find the source here. It shows, amongst other things, the communication between Cljs and Hy via Transit.

For the (naturally unspectacular) on-line version, I had to upload the code for Hy and Transit to the cgi-bin of the server (all respective modules are in the .egg zip-files of the repository). Note: The Hy repl feature is turned off in the on-line version.

I also added a backend written in Phel, a Clojure inspired Lisp that compiles to PHP (thanks @John_Shaffer for the hint).

Pretty cool. There’s a similar language called Phel that compiles Clojure-ish LISP to PHP.

Hi @John_Shaffer, do you know of any website+repository demonstrating Phel+Transit-php in action? There are always some details to solve.
For example I needed to find a Python implementation of Clojure’s postwalk function to replace Hy-Keywords with Transit-Keywords before being able to send a dictionary/hash-map from server to client. Or I created .egg files (I used the package pyassembly) to be able to install Hy on the host via ftp.
In fact, the main reason for posting here was the hope to gather some information about best practices with Clojurescript plus Lisp (Hy, Phel, CljPerl, …) on cheap shared hosting services.

Personally, I’ve always used JSON for cross-language requests. For transit, it looks like you could use either the postwalk approach or copy Transit.php and replace a few of the handlers with Phel-native type handlers.

IMO, the best practices for shared hosting are: “Don’t use shared hosting”. It is too limited and is usually more expensive than cloud hosting. Internationally, you can get a DO Droplet or LightSail instance with 1 GB of RAM for $5/mo which can run Clojure just fine. If using babashka/GraalVM/Hy/Phel/CljPerl, you can use a 512 MB LightSail for $3.50/mo. It might be a bit more expensive if it has to be local, but a quick search turns up Ventus and maybe Hetzner.

Thank you for the “use JSON + cloud hosting as best practice” advice. Another possibility that came up in our Clojure group is this post about deployment of Clojure+Datahike on Heroku.
Looking for Clojure experience on “Average Joe’s” hosting is probably not rationally justifiable (sigh).

I think it’s fine to use Transit too, as long as you’re willing to spend a few hours getting the output the way you want it. Setting up Transit sounds a lot better than trying to bolt on date representations, etc. to JSON.

I use JSON for cross-language requests because I have several different components written in different languages (Go & Lua) that make HTTP requests for very simple data, just a few strings and numbers. JSON is perfect for that scenario. Elsewhere I have Clojure/ClojureScript using Transit, which is what I prefer for handling more complex data.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.