Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now that we’ve built a minimum viable Elixir project, let’s turn our attention to the Phoenix framework. The first thing we need to do to incorporate Phoenix into our Elixir project is to install a few dependencies. We’ll start by adding a `deps` array to the `project/0` callback in our `mix.exs` file. In `deps` we’ll list `:phoenix`, `:plug_cowboy`, and `:jason` as dependencies. By default, Mix stores downloaded dependencies in the `deps/` folder at the root of our project. Let’s be sure to add that folder to our `.gitignore`. Once we’ve done that, we can install our dependencies with `mix deps.get`. The reliance on `:phoenix` makes sense, but why are we already pulling in `:plug_cowboy` and `:jason`? Under the hood, Phoenix uses the [Cowboy](https://github.com/ninenines/cowboy) web server, and [Plug](https://github.com/elixir-plug/plug) to compose functionality on top of our web server. It would make sense that Phoenix relies on `:plug_cowboy` to bring these two components into our application. If we try to go on with building our application without installing `:plug_cowboy`, we’ll be greeted with the following errors: ** (UndefinedFunctionError) function Plug.Cowboy.child_spec/1 is undefined (module Plug.Cowboy is not available) Plug.Cowboy.child_spec([scheme: :http, plug: {MinimalWeb.Endpoint, []} ... Similarly, Phoenix relies on a JSON serialization library to be installed and configured. Without either `:jason` or `:poison` installed, we’d receive the following warning when trying to run our application: warning: failed to load Jason for Phoenix JSON encoding (module Jason is not available). Ensure Jason exists in your deps in mix.exs, and you have configured Phoenix to use it for JSON encoding by verifying the following exists in your config/config.exs: config :phoenix, :json_library, Jason Heeding that advice, we’ll install `:jason` and add that configuration line to a new file in our project, `config/config.exs`.
- Loading branch information