Ace: HTTP/2 webserver

Ace 0.15.9 Released

Default start_link and child_spec functionality can be set up by using Ace.HTTP.Service

New

defmodule MyApp do
  use Ace.HTTP.Service, [port: 8080, cleartext: true]

  def handle_request(%{method: :GET, path: []}, %{greeting: greeting}) do
    response(:ok)
    |> set_header("content-type", "text/plain")
    |> set_body("#{greeting}, World!")
  end
end

config = %{greeting: "Hello"}

MyApp.start_link(config, [port: 1234])
# [info] Serving cleartext using HTTP/1 and HTTP/2 on port 1234
# => {:ok, service}

Add to supervision tree

children = [
  {MyApp, [%{greeting: "Hello"}, [port: 1234]]},
]

Previously

defmodule MyApp do
  use Raxx.Server

  @impl Raxx.Server
  def handle_request(%{method: :GET, path: []}, %{greeting: greeting}) do
    response(:ok)
    |> set_header("content-type", "text/plain")
    |> set_body("#{greeting}, World!")
  end
end

application = {MyApp, %{greeting: "Hello"}}
options = [port: 1234, cleartext: true]

Ace.HTTP.Service.start_link(application, options)
# [info] Serving cleartext using HTTP/1 and HTTP/2 on port 1234
# => {:ok, service}
2 Likes