Phoenix is productive, reliable, fast web framework. In this presentation, we will be talking about what making Phoenix unique. We will discuss using OTP features alongside with Phoenix.Endpoint. Also, we will discuss Phoenix future changes.
Elixir Meetup 4 Lviv (17.12.2016)
9. In Elixir (actually, in Erlang/OTP), an application is a component
implementing some specific functionality, that can be started and
stopped as a unit, and which can be re-used in other systems.
11. Endpoint
● handles all aspects of
requests up until the point
where the router takes
over
● provides a core set of plugs
to apply to all requests
● dispatches requests into a
designated router
16. The Router
● parses incoming requests and dispatches
them to the correct controller/action,
passing parameters as needed
● provides helpers to generate route paths
or urls to resources
● defines named pipelines through which
we may pass our requests
● Pipelines
o allow easy application of groups of
plugs to a set of routes
17. Controllers
● provide functions, called actions,
to handle requests
● Actions
o prepare data and pass it into
views
o invoke rendering via views
o perform redirects
49. Phoenix.Transports
The transport allows to abstract away how upper layer i.e.
channels receives or sends messages. Channels only need to
call the right function of transport module and let it handle
the raw work of communication.
50. Channel
Channel has two components, one is the channel behavior
implemented by the developer and the second is the channel
GenServer that is spawned up by phoenix that consumes the
developer written module.
Communicating with the transport (receiving from &
sending to transport)
Listening for requests to send a message that was
broadcasted
58. join(topic, auth_msg, socket)
To authorize a socket in join/3, return {:ok, socket}.
To refuse authorization in join/3, return {:error, reply}.
59. handle_in(event, payload, socket)
After a client has successfully joined a channel, incoming
events from the client are routed through the channel’s
handle_in/3 callbacks
60. Replay
In addition to pushing messages out when you receive a
handle_in event, you can also reply directly to a client event
for request/response style messaging
61. Intercept & handle_out/3
When an event is broadcasted with broadcast/3, each channel
subscriber can choose to intercept the event and have their
handle_out/3 callback triggered
intercept ["new_msg", "user_joined"]
So on “new_msg” and “user_joined” topics handle_out will be
triggered
63. Terminate
On termination, the channel callback terminate/2 will be
invoked with the error reason and the socket.
If we are terminating because the client left, the reason will be
{:shutdown, :left}. Similarly, if we are terminating because the
client connection was closed, the reason will be {:shutdown,
:closed}.
If any of the callbacks return a :stop tuple, it will also trigger
terminate with the reason given in the tuple.