October 2019
Intermediate to advanced
358 pages
8h 22m
English
Elixir is perhaps the first functional language to support Lisp-style macros with a more natural syntax. This feature, like a template for code, is not always the right tool for everyday users, but macros are invaluable for extending the Elixir language to add the common features all web servers need to support.
For example, web servers need to map routes onto functions that do the job:
| | pipeline :browser do |
| | plug :accepts, ["html"] |
| | plug :fetch_session |
| | plug :protect_from_forgery |
| | end |
| | |
| | pipeline :api do |
| | plug :accepts, ["json"] |
| | end |
| | |
| | scope "/", MyApp do |
| | pipe_through :browser |
| | |
| | get "/users", UserController, :index |
| | ... |
| | end |
| | |
| | scope "/api/", MyApp do |
| | pipe_through :api |
| | |
| | ... |
| | end |
You’ll see this code a little later. ...
Read now
Unlock full access