I’ve been playing around with elm-concurrent-task and what a backend http setup could look like with it. I ended up implementing the realworld backend api spec with it; I had a lot of fun in the process!
(Please correct me if I’m wrong) I think this is the first backend spec compliant Elm implementation.
I’m using something close to this in production, it’s low traffic but it behaves well!
Yep you’re right about the rate limiter, the server endpoints are all stateless but underneath there’s the stateful program:
You could add logic + state for rate limiting at this level if you wanted.
Making sure requests + responses aren’t mixed up is a clever trick (credit to @eberfreitas) where you create a new Promise on request and pass the resolve function through Elm (as an Json.Encode.value). When the response is ready, JS calls the passed resolve function.
It’s pretty handy as it makes it very easy to use with any server framework.