Making Our Server into a Component
Explore how to transform a basic Elixir server into a reusable component by splitting its API, implementation, and server modules. Understand the benefits of this approach for managing complex business logic, facilitating easier testing, and maintaining modular server code in Elixir using OTP.
We'll cover the following...
Earlier, we said that what Elixir calls an application, most people would call a component or a service. That’s certainly what our sequence server is: a freestanding chunk of code that generates successive numbers.
Implementation
Our implementation puts three things into a single source file:
- The API.
- The logic of our service (adding one).
- The implementation of that logic in a server.
Have another look at the code in the previous lesson. If we didn’t know what it did, how would we find out? Where’s the code that does the component’s logic? Imagine working with a really complex one with lots of logic. That’s why we’re experimenting with splitting the API, implementation, and server into three separate files.
We’ll put the API ...