Introducing Lean Server for Midas

Lean server is a HTTP server written in Gleam (Gleam is a new type safe language for the Erlang virtual machine (BEAM)). Lean is the built-in server for the Midas Web Framework


        import midas/lean.{MaxConcurrency}
        import gleam/http

        fn handle(_request) {
          http.response(200)
          |> http.set_body("Hello, World!")
        }

        fn start_link() {
          lean.start_link(handle, 8080, [MaxConcurrency(100000)])
        }
      

Why Lean?

Lean incorperates the lessons I learnt while developing Ace and Raxx. Ace is a HTTP server written in Elixir that aimed to abstract away the differences between HTTP/1 and HTTP/2. Ace also supported HTTPS and long lived connections for streaming requests/responses.

In my opinion Ace was successful in its goals. However, having all these features in one server increased the implementation complexity. Since starting Ace I have written several service that use the same narrow subset of features. These applications were mostly JSON API services, they did not have streaming. Being deployed behind a load balancer, they needed neither HTTPS or HTTP/2.

Lean aims to be focus on these API applications and has a sizeable list of non-goals:

By not tackling all these non-goals Lean should be simpler and therefore easier to maintain. This should make it easier to address features and bugs, as well as easier to contribute to. It should also be faster, though I have yet to test this.

Of course, all the features listed above are important for a framework. By writing adapters for other servers, such as Ace or Cowboy, Midas the framework will be able to support all these features.

Why Gleam

For now Gleam feels like the most promising approach to getting the benefits of types on the BEAM. This is something that has been on several peoples wish list, including mine, for quite a long time.

Gleam compiles to readable Erlang (if "readable Erlang" isn't a controversial statement) It also has great interop with Erlang and Elixir. Because of these features I would argue that it can be considered "production ready", if only for parts of an application. There are some parts of your application that will benefit more from type safety than others.

I will write more on this topic at some later time.

Using Lean Server

Lean Sever is bundled as part of Midas. Currently Midas is using features that are not yet part of a Gleam stable release, therefore you will need to use it as a git dependency from `midas-framework/midas`.