Responding with html.eex files
Now that we know how to use EEx
to create templates using Elixir, it’s time to start responding with embedded Elixir with our HTTP server.
Let’s start by creating a new mix
project:
$ mix new example_server_html_eex
In order to use Goldcrest
with this new app, let’s start by adding goldcrest
as a mix
dependency in example_server_html_eex
:
mix.exs
defmodule ExampleServerHtmlEex.MixProject do # .. defp deps do [ {:goldcrest, "~> 0.0.1"} ] end end
We can fetch the dependency by running $ mix deps.get
, and once fetched, let’s add a Router
module. This router will be very similar to the one we created in Chapter 5, with the only difference being the content type of the response. For this router, we will respond with the text/html
content:
lib/example_server_html_eex/router.ex
...