⚠️ This post links to an external website. ⚠️
For the past few weeks, I’ve been building an Elixir package. As part of that process, I’ve been studying well-established codebases to understand how experienced teams structure their APIs — one of them being Phoenix. While exploring the Phoenix.Controller module, I came across a line that immediately stood out:
defdelegate get_csrf_token(), to: Plug.CSRFProtectionIt looked simple, but it raised an important question: why delegate a function instead of calling it directly? In this article, we’ll break down how Elixir’s defdelegate works, and more importantly, why it matters. You’ll see how it helps you design APIs that stay stable even as your internal implementation changes — without breaking your clients. If you’re coming from languages like JavaScript, this might feel similar to certain design patterns — but in Elixir, it’s built right into the language.
continue reading onmedium.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.