Before we delve into the topic of data gathering in Elixir/Phoenix, let us focus on another core aspect of our uptime monitor application: routing and

Uptime monitor in Elixir & Phoenix: Routing and controllers

submited by
Style Pass
2021-09-23 11:30:03

Before we delve into the topic of data gathering in Elixir/Phoenix, let us focus on another core aspect of our uptime monitor application: routing and controllers.

Welcome to the fourth part of the article series where we are creating an Uptime Monitor in Elixir. As we said in the previous article, there was a plan to work with data gathering in this part. However, in my opinion, there is one core aspect we should focus on before. This is routing and controllers.

The Router is a big hub of the Phoenix application, where all the requests are dispatched to the right controllers. We had a brief look into the Router while creating authentication and authorization in Elixir/Phoenix application. Let’s take a look at it once again.

The first line in the EMeterWeb.Router module, which is use EMeterWeb, :router, simply makes Phoenix routing functions available in this module. It runs a macro from the >router function in the EMeterWeb module.

The next line - import EMeterWeb.UserAuth, includes authorization functions: redirect_if_user_is_authenticated/2 and require_authenticated_user/2 provided by mix phx.gen.auth in the EMeterWeb.UserAuth module. Those functions are used as plugs further in the module.

Leave a Comment