Elixir Diary Day 2: Reading Phoenix docs
Elixir Diary Day 2: Reading Phoenix docs

Elixir Diary Day 2: Reading Phoenix docs

Tags
Elixir
Published
Author

Day 2 - Reading Phoenix guides cover to cover

Today I decided learning by reading the docs cover to cover first. After going through the guides. I find that journaling helps me. Here’s some personal notes :
  • Plugs
    • There are functions and module plugs. In Phoenix, it lets you manipulate the HTTP connection. Encourage you to have flat, more reusable code by composing plugs. You can use halt(conn) to not interpret the next plug.
  • Pipeline
    • Inside a pipeline you can chain different plugs. You use pipe_trough .
  • Module
    • Same thing as namespaces, it help organizing code.
  • Path helpers
    • Given a controller and a verb, it returns a path. Useful for links in views.
  • Views
    • Using assign(conn, :my_thing, 42) in the controller, call<%= my_thing %> inside the template.
  • resources macro
    • It’s a Phoenix macros. It’s for declaring routes in batch, you can omit certain subset of routes with only or except. Like resources ... it will take a controller, and create troutes. Routes can be nested.
  • scope macro
    • You can have scope inside Router, for hard versioning an API for instance. However you can’t have two routes with the same alias and the same path.
  • mix phx.routes output the map fo your app
 
So many different concepts, I’m never sure how use the macros : scope, plug, pipe_through .