Functional Web Development with Elixir, OTP, and Phoenix

Book description

Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web applications. For decades OTP has helped developers create incredibly robust, scalable applications with unparalleled uptime. Make the most of them as you build a stateful web app with Elixir, OTP, and Phoenix. Model domain entities without an ORM or a database. Manage server state and keep your code clean with OTP Behaviours. Layer on a Phoenix web interface without coupling it to the business logic. Open doors to powerful new techniques that will get you thinking about web development in fundamentally new ways.

Elixir and OTP provide exceptional tools to build rock-solid back-end applications that scale. In this book, you'll build a web application in a radically different way, with a back end that holds application state. You'll use persistent Phoenix Channel connections instead of HTTP's request-response, and create the full application in distinct, decoupled layers.

In Part 1, start by building the business logic as a separate application, without Phoenix. Model the application domain with Elixir functions and simple data structures. By keeping state in memory instead of a database, you can reduce latency and simplify your code. In Part 2, add in the GenServer Behaviour to make managing in-memory state a breeze. Create a supervision tree to boost fault tolerance while separating error handling from business logic.

Phoenix is a modern web framework you can layer on top of business logic while keeping the two completely decoupled. In Part 3, you'll do exactly that as you build a web interface with Phoenix. Bring in the application from Part 2 as a dependency to a new Phoenix project. Then use ultra-scalable Phoenix Channels to establish persistent connections between the stateful server and a stateful front-end client.

You're going to love this way of building web apps!

What You Need:

You'll need a computer that can run Elixir version 1.5 or higher and Phoenix 1.3 or higher. Some familiarity with Elixir and Phoenix is recommended.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Introduction
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. About This Book
    4. Online Resources
  3. 1. Mapping Our Route
    1. Lay the Foundation with Elixir
    2. Add a Web Interface with Phoenix
    3. Functional Web Development
    4. The Game of Islands
  4. Part I. Define the Functional Core in Elixir
    1. 2. Model Data and Behavior
      1. The Benefits
      2. Let’s Build It
      3. Discover the Entities and Model the Domain
      4. Transforming Data
      5. Putting the Pieces Together
      6. Wrapping Up
    2. 3. Manage State with a State Machine
      1. A Quick Look at State
      2. A Bit of History
      3. State Machines
      4. A Functional State Machine for Islands
      5. Working Through the States
      6. Wrapping Up
  5. Part II. Add OTP for Concurrency and Fault Tolerance
    1. 4. Wrap It Up in a GenServer
      1. A Look at Micro-Services
      2. OTP Solutions
      3. Getting Started with GenServer
      4. Initializing GenServer State
      5. Customizing GenServer Behavior
      6. Naming GenServer Processes
      7. Wrapping Up
    2. 5. Process Supervision for Recovery
      1. Fault Tolerance
      2. Linking Processes
      3. Introducing the Supervisor Behaviour
      4. Supervision Strategies
      5. The Child Specification
      6. A Supervisor for the Game
      7. Starting the Supervision Tree
      8. Starting and Stopping Child Processes
      9. Putting the Pieces Together
      10. Recovering State After a Crash
      11. Wrapping Up
  6. Part III. Add a Web Interface with Phoenix
    1. 6. Generate a New Web Interface with Phoenix
      1. Frameworks
      2. Applications
      3. Generate a New Phoenix Application
      4. Adding a New Dependency
      5. Call the Logic from the Interface
      6. Wrapping Up
    2. 7. Create Persistent Connections with Phoenix Channels
      1. The Beauty of Channels
      2. The Pieces That Make a Channel
      3. Let’s Build It
      4. Establish a Client Connection
      5. Converse Over a Channel
      6. Connect the Channel to the Game
      7. Phoenix Presence
      8. Authorization
      9. Wrapping Up
  7. A1. Installing System Dependencies
    1. Elixir
    2. Erlang
    3. Phoenix
    4. Node.js and NPM
  8.  Bibliography

Product information

  • Title: Functional Web Development with Elixir, OTP, and Phoenix
  • Author(s): Lance Halvorsen
  • Release date: January 2018
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680505443