11 Working with components

 

This chapter covers

  • Creating OTP applications
  • Working with dependencies
  • Building a web server
  • Configuring applications

It’s time to turn our attention toward producing releasable systems that can be deployed. To reach that goal, you need to learn about OTP applications, which let you organize your system into reusable components. Applications are a standard way of building Elixir or Erlang production systems and libraries. Relying on them brings various benefits, such as dependency management; simplified system starting; and the ability to build standalone, deployable releases.

In this chapter, you’ll learn how to create applications and work with dependencies. In the process, you’ll turn your to-do system into a proper OTP application and use some third-party libraries from the Erlang and Elixir ecosystem to expose an HTTP interface for your existing system. There’s a lot of work ahead, so let’s get started with OTP applications.

11.1 OTP applications

An OTP application is a component that consists of multiple modules and that can depend on other applications. This makes it possible to start the entire system with a single function call. As you’re about to see, it’s reasonably easy to turn code into an application. Your current version of the to-do system is already an OTP application, but there are some minor details you can improve. You’ll see this in action shortly; first, let’s look at what OTP applications consist of.

11.1.1 Creating applications with the mix tool

11.1.2 The application behavior

11.1.3 Starting the application

11.1.4 Library applications

11.1.5 Implementing the application callback

11.1.6 The application folder structure

11.2 Working with dependencies

11.2.1 Adding a dependency

11.2.2 Adapting the pool

11.2.3 Visualizing the system

11.3 Building a web server

11.3.1 Choosing dependencies

11.3.2 Starting the server