Plugs

Plugs implement two fts init and call which takes in a conn and return a conn

Fetchable Fields

Must fetch them before use, best placed in the router.ex plug list. For example, the cookies field uses fetch_cookies/2.

  • cookies- the request cookies with the response cookies

  • body_params - the request body params, populated through a Plug.Parsers parser.

  • query_params - the request query params, populated through fetch_query_params/2

  • path_params - the request path params, populated by routers such as Plug.Router

  • params - the request params, the result of merging the :path_params on top of :body_params on top of :query_params

  • req_cookies - the request cookies (without the response ones)

Functions

Ft

Effect

Assigns a value to a key in the connection.

Stops the plug pipeline . See

Sends a response with the given status and body.

Custom Plug

react_phoenix_web/plugs

some controller

Auth Example

Usage conn.assigns.current_user

router.ex

lib/discuss_web/plugs/auth.ex

app.html.eex

Last updated