I never fully understood how Phoenix is able to route urls with params like "users/1" to the correct Controller, Action. From what I understand Phoenix pattern matches the path on incoming requests. For example, its easy to see how "/users" will match this get macro.
get "/users", UserController, :index
But how does Phoenix route "/users/1" to this.
get "/users/:id", UserController, :show
How does Phoenix match "/users/1" to "/users/:id"
I know it can’t be traditional pattern matching otherwise you’d get a no function clause matching error.
There must be some kind of macro magic happening behind the scenes that I don’t understand.
Thanks, I was hoping I wouldn’t have to take a deep dive into the source but in order to understand what’s going on under the hood looks like I have no choice.
I was always curios how the Router layer worked in Phoenix. For any one interested about 31:22 Chris explains how routes work. I also purchased Metaprogramming Elixir, used my Elixir Forum discount and got it for 7 bucks. What a steal!