Book Image

Mastering Elixir

By : André Albuquerque, Daniel Caixinha
Book Image

Mastering Elixir

By: André Albuquerque, Daniel Caixinha

Overview of this book

Running concurrent, fault-tolerant applications that scale is a very demanding responsibility. After learning the abstractions that Elixir gives us, developers are able to build such applications with inconceivable low effort. There is a big gap between playing around with Elixir and running it in production, serving live requests. This book will help you fll this gap by going into detail on several aspects of how Elixir works and showing concrete examples of how to apply the concepts learned to a fully ?edged application. In this book, you will learn how to build a rock-solid application, beginning by using Mix to create a new project. Then you will learn how the use of Erlang's OTP, along with the Elixir abstractions that run on top of it (such as GenServer and GenStage), that allow you to build applications that are easy to parallelize and distribute. You will also master supervisors (and supervision trees), and comprehend how they are the basis for building fault-tolerant applications. Then you will use Phoenix to create a web interface for your application. Upon fnishing implementation, you will learn how to take your application to the cloud, using Kubernetes to automatically deploy, scale, and manage it. Last, but not least, you will keep your peace of mind by learning how to thoroughly test and then monitor your application.
Table of Contents (18 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
5
Demand-Driven Processing
Index

Routing requests


We'll now explore the flow of a traditional HTTP request, analyzing each step of the process up to when a response is rendered. As we've seen in the last section, Plug provides an adapter for the Cowboy web server, which we've used to demonstrate the two plugs we've created. Phoenix also uses this adapter to interact with the Cowboy web server. When a requests hits the server, this adapter handles it, creates a new conn (a %Plug.Conn{} struct), and calls the endpoint configured in your application. By default, the endpoint is called <name_of_your_app>.Endpoint. The endpoint is the boundary between the web server and our application code, so essentially the endpoint is the beginning of a request. Let's see the configuration for the endpoint:

$ cat apps/elixir_drip_web/config/config.exs

config :elixir_drip_web, ElixirDripWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "ez09 ...9cbq",
  render_errors: [view: ElixirDripWeb.ErrorView, accepts: ~w(html json...