handleRequest : ClientRequest Value -> Task (ServerError Value) (ServerResponse Value)
handleRequest request =
case request.url of
ok (Json.Encode.string "hello world")
ok (Json.Encode.string ("hello " ++ name))
At Nomalab we’ve been using Elm on the backend for 2.5 years and I personaly find it quite beautiful! But it slowly became a pain because we had to develop kernel stuff for the DB, logging, crypto, an automatic JSON serialization/deserialization library… We knocked ourselves on the door with 0.19. Many mistakes were made in the process anyways, we especially made it hard to debug. The new backend guy felt alianated (knowing Scala and Haskell), so we’ve decided to slowly ditch Elm from our backend. End of story o/
But this experience allowed me to explore some aspects of what could be done with Elm, right now. First, it’s stateless by design: processing a request quite matches the concept of Elm’s
Task with chaining; the downside being that you can’t parralelize
Task, or develop custom kernel
Task. That’s not a huge deal though, since most of the time each operation depends on the previous one and it makes it much easier to recover if it goes badly. The other aspect is that as of today most services (DB, logging, emailling, pub/sub…) are reachable with
Http so we already have everything we need to build some kind of smart proxy.
What’s very missing to make it even better?
- a logging api (in the mean time you can send back to JS in the response)
- a fast & solid crypto api (in the mean time there are some libs available, beware)
- an official Http shim (the xhr npm package supports
GET file:// !)
It’s also serveless compliant (being stateless), and I’ve been very keen to see Cloudflare’s ServiceWorker which is the browser’s ServiceWorker api, running on the edge of Cloudflare’s network. If you don’t know any of this, I invite you to check it out, but basically ServiceWorkers in your browser are shared accross all tabs and intercept http requests to allow you to manage cache or auth, among other things. On Cloudflare, it’s basically a programmable (a function) cache and proxy service (think auth, cache, html rendering…). I’m wondering if this is in the community radar?