Plugifying our HTTP server
To leverage the power of Plug for routing, error handling, and other uses, let’s define a Plug
adapter for the Goldcrest.HTTPServer
package.
Let’s start by defining a new package, plug_goldcrest_http_server
:
$ mix new plug_goldcrest_http_server --module Plug.Goldcrest.HTTPServer
Now, let’s add :goldcrest_http_server
and plug
to our Mix dependencies:
lib/plug/goldcrest/http_server/conn.ex
defmodule Plug.Goldcrest.HTTPServer.MixProject do use Mix.Project # .. defp deps do [ {:goldcrest_http_server, "~> 0.0.1"}, {:plug, "~> 1.12.1"} ] end end
Now, we can fetch the dependencies by running the following command:
$ mix deps.get
In this newly generated mix project, we can start by defining an adapter for Plug.Conn
. Let’s...