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 cookiesbody_params- the request body params, populated through aPlug.Parsersparser.query_params- the request query params, populated throughfetch_query_params/2path_params- the request path params, populated by routers such asPlug.Routerparams- the request params, the result of merging the:path_paramson top of:body_paramson top of:query_paramsreq_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
Return status
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