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:

Endpoint configuration

All endpoints are configured directly in the Phoenix application environment. For example:

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

Phoenix configuration is split in 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.

On the other hand, runtime configuration is accessed during or after your application is started and can be read through the config/2 function:

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

Compile-time

Runtime

Web server

Starting an endpoint as part of a web server can be done by invoking YourApp.Endpoint.start/0. Stopping the endpoint is done with YourApp.Endpoint.stop/0. The web server is configured with the :http and :https options defined above.

The endpoint also provides a url/1 function that generates a url with the given path according to the :url configuration above:

MyApp.Endpoint.url("/foo/bar")
#=> "http://example.com/foo/bar"
Source

Summary

plug(plug, opts \\ [])

Stores a plug to be executed as part of the pipeline

router(conn, plug)

A macro that can be plugged in order to handle routing errors

Macros

plug(plug, opts \\ [])

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

Source
router(conn, plug)

A macro that can be plugged in order to handle routing errors.

By default, a Phoenix router will raise a Phoenix.Router.NoRouteError struct in case no route is found. This macro wraps the router call so the route error does not pass through.

It also wraps the router call to provide better debugger and error rendering behaviour.

Examples

plug :router, MyApp.Router
Source