Phoenix.Endpoint

Defines a Phoenix endpoint.

The endpoint is the boundary where all requests to your web application start. It is also the interface your application provides to the underlying web servers.

Overall, an endpoint has three responsibilities:

Endpoints

An endpoint is simply a module defined with the help of Phoenix.Endpoint. If you have used the mix phoenix.new generator, an endpoint was automatically generated as part of your application:

defmodule YourApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :your_app

  # plug ...
  # plug ...

  plug :router, YourApp.Router
end

Before being used, an endpoint must be explicitly started as part of your application supervision tree too (which is again done by default in generated applications):

supervisor(YourApp.Endpoint, [])

Endpoint configuration

All endpoints are configured in your application environment. For example:

config :your_app, YourApp.Endpoint,
  secret_key_base: "kjoy3o1zeidquwy1398juxzldjlksahdk3"

Endpoint configuration is split into two categories. Compile-time configuration means the configuration is read during compilation and changing it at runtime has no effect. The compile-time configuration is mostly related to error handling.

Runtime configuration, instead, is accessed during or after your application is started and can be read and written through the config/2 function:

YourApp.Endpoint.config(:port)
YourApp.Endpoint.config(:some_config, :default_value)

Compile-time configuration

Runtime configuration

Endpoint API

In the previous section, we have used the config/2 function which is automatically generated in your endpoint. Here is a summary of all the functions that are automatically defined in your endpoint.

Paths and URLs

Channels

Endpoint configuration

Plug API

Source

Summary

plug(plug, opts \\ [])

Stores a plug to be executed as part of the pipeline

Macros

plug(plug, opts \\ [])

Stores a plug to be executed as part of the pipeline.

Source