Phoenix in Action
Geoffrey Lessel
  • MEAP began November 2017
  • Publication in June 2019 (estimated)
  • ISBN 9781617295041
  • 336 pages (estimated)
  • printed in black & white

This book gives an excellent step by step introduction to Phoenix.

Samuel Bosch
Phoenix is a modern web framework built for the Elixir programming language. Elegant, fault-tolerant, and performant, Phoenix is as easy to use as Rails and as rock-solid as Elixir's Erlang-based foundation. Phoenix in Action builds on your existing web dev skills, teaching you the unique benefits of Phoenix along with just enough Elixir to get the job done.
Table of Contents detailed table of contents

Part 1: An introduction

1 Ride the Phoenix

1.1 What is Phoenix?

1.2 Elixir and Phoenix vs. the alternatives

1.2.1 Real-time communication

1.2.2 Efficient, small processes

1.2.3 Background computation

1.2.4 Minimal hardware requirements, low-cost scaling

1.2.5 It’s not all roses

1.3 The power of Elixir

1.3.1 Scalability

1.3.2 Supervision trees

1.3.3 Erlang VM

1.3.4 Macro and metaprogramming support

1.3.5 OTP

1.4 Functional vs. object-oriented programming

1.4.1 Overview of functional programming

1.5 Keep reading

1.6 Summary

2 Intro to Elixir

2.1 The basics

2.1.1 IEx

2.1.2 Basic types

2.1.3 A small detour into functions

2.1.4 Data type details

2.1.5 Back to modules and named functions

2.1.6 alias

2.1.7 import

2.2 Other idiomatic Elixir language features

2.2.1 The pipe operator

2.2.2 Pattern matching

2.2.3 Using IEx.Helpers.v/1

2.3 Summary

3 A little Phoenix overview

3.1 Follow the data

3.1.1 The basics of a web request

3.1.2 Endpoint

3.1.3 Router

3.1.4 Controller


3.1.6 Templates

3.2 Putting it all together

3.3 Summary

Part 2: The Basics

4 Phoenix is not your application

4.1 I thought this book was about Phoenix

4.2 The first steps in building your application

4.2.1 Defining an item

4.2.2 Adding a fake database

4.2.3 Getting an Item by id

4.2.4 Getting an Item based on other information

4.3 Next steps

4.4 Summary

5 Elixir application structure

5.1 Moving from a single file to an application

5.1.1 Using Mix to create a new application

5.1.2 Generating an auction umbrella application

5.1.3 The magic mix.exs file

5.2 Organizing, compiling, and running your new application

5.2.1 Breaking apart the three modules

5.2.2 Compile and run!

5.2.3 Running the Auction application for the first time

5.3 Using hex to get external dependencies

5.3.1 Pulling in your dependencies

5.4 Summary

6 Bring in Phoenix

6.1 Installing Phoenix on your system

6.2 Creating a new Phoenix application

6.2.1 Running your server for the first time

6.3 Listing items from the fake repo

6.3.1 Modifying the controller and template

6.4 Summary

7 Being persistent with a database

7.1 A quick intro to Ecto

7.2 Configuring Ecto

7.2.1 Using Ecto’s Mix tools to set up your database

7.3 Preparing Auction to use the database

7.3.1 Defining the Auction.Item schema

7.3.2 Migrating the database

7.3.3 Pointing the public interface to the new repo

7.3.4 Instructing the application to supervise the database connection

7.3.5 Testing it out

7.4 Creating, retrieving, and deleting data in the database

7.4.1 Inserting data

7.4.2 Retrieving data

7.4.3 Deleting data

7.4.4 Updating data

7.4.5 What about the website?

7.5 Summary

8 Making changes with Ecto.Changeset

8.1 Can’t I just …​ update?

8.1.1 A brief intro to changesets

8.1.2 Creating a changeset for Auction.Item

8.2 Now you can update!

8.2.1 Adjusting the public interface for updating

8.3 Summary

9 Transforming data in your browser

9.1 Handling new routes in your application

9.1.1 Adding a new route

9.1.2 Adding a new controller

9.1.3 Adding a new view

9.1.4 Adding a new template

9.2 Viewing the details of a single item

9.2.1 Defining the show route and function

9.2.2 Defining the show.html template

9.2.3 Linking to individual items

9.3 Creating items through web forms

9.3.1 Defining the new and create routes

9.3.2 Defining the “new” controller function

9.3.3 Defining the “new” template

9.3.4 Defining the create controller function

9.4 Editing items through web forms

9.4.1 Defining the edit and update routes

9.4.2 Defining the “edit” controller function

9.4.3 Defining the edit.html.eex template

9.4.4 Defining AuctionWeb.ItemController.update/2

9.5 Summary

10 Plugs, assigns, and dealing with session data

10.1 Preparing your application for user registration

10.1.1 Defining the Auction.User schema

10.1.2 Creating a migration to create the users table

10.1.3 Defining changesets for Auction.User

10.1.4 Creating API functions in Auction

10.1.5 User registration web flow

10.2 Handling user login and sessions

10.2.1 Creating the route, controller, view, and templates for logging in and out

10.2.2 Implementing the dirty details of sessions and authentication

10.3 Plugs

10.4 Adding site navigation

10.4.1 Implementing the log out function

10.5 Restricting users from certain pages

10.6 Summary

11 Associating records and accepting bids

11.1 Creating bids

11.2 Adding associations to the Auction.Bid schema

11.2.1 A little detour into associations

11.2.2 Creating a migration that describes the associations

11.2.3 Creating a form to accept bids

11.3 Using has_many with items and users

11.3.1 Preloading and avoiding N+1 queries

11.3.2 Preloading associations in the public interface module and controller

11.3.3 Adding the list of bids to the view template

11.4 Listing a user’s bids on their profile page

11.4.1 Using Ecto.Query to construct database queries

11.4.2 Making a view helper function global and using the bids assign

11.4.3 Using Timex to format dates and times

11.5 Some ideas for further improvement

11.6 Summary

Part 3: Getting Advanced

12 Using Phoenix channels for real-time communication

12.1 What are Phoenix channels?

12.2 Connecting a user to a channel and a topic

12.2.1 Handling topic join requests

12.2.2 Getting the user’s browser to join a topic

12.3 Sending real-time messages to a user

12.3.1 Receiving messages in the user’s browser

12.3.2 Configuring the channel to handle messages

12.3.3 Sending your browser a message from IEx

12.4 Updating all users when a new bid is made

12.4.1 Refactoring the rendering of an item’s bids

12.4.2 Modifying the controller to broadcast a message

12.4.3 Handling the broadcasted HTML in the browser

12.5 Summary

13 Building an API

13.1 Scoping API requests to a new controller

13.2 Creating the AuctionWeb.Api.ItemController controller and view

13.4 Summary

14 Testing in Elixir and Phoenix

14.1 An introduction to ExUnit

14.1.1 Writing a first test

14.2 Setting up tests for Ecto

14.2.1 Configuring a new database

14.2.2 Creating a sandbox and configuring Ecto to use it in tests

14.2.3 Setting up the database before tests run

14.2.4 Creating a Mix alias for use during test runs

14.3 Testing Ecto queries in Auction

14.3.1 Testing Auction.list_items/0

14.3.2 Testing Auction.get_item/1

14.3.3 Testing Auction.insert_item/1

14.4 Simultaneously writing documentation and tests with doctests

14.4.1 Writing function-level documentation

14.4.2 Viewing documentation in IEx

14.4.3 Viewing documentation with ExDoc

14.4.4 Adding examples and doctests

14.4.5 Module-level documentation

14.5 Writing tests For Phoenix

14.5.1 Testing that an item is added to the database on success

14.5.2 Testing that you’re redirected to the new item on success

14.5.3 Testing that no item is created on error

14.5.4 Testing that the new item form is rendered on error

14.5.5 The entire ItemControllerTest module

14.6 What next?

14.7 Summary


Appendix A: Installing Elixir and Phoenix

A.1 Installing Elixir

A.1.1 macOS and Unix/Linux variants

A.1.2 Windows

A.1.3 From source

A.1.4 Installing Erlang

A.2 Installing Phoenix

A.2.1 PostgreSQL

A.2.2 Node.js

Appendix B: More Elixir resources

B.1 On the web

B.2 Books

B.3 Community

About the Technology

Phoenix is a web framework for the Elixir language. Phoenix applications are blazingly fast, and as a developer you’ll appreciate the attention to detail in the framework design that makes you super-productive almost immediately. In particular, Phoenix channels provide an easy way to set up and manage real-time communication. Phoenix runs on the battle-tested Erlang virtual machine, so your apps are guaranteed to be rock-solid.

About the book

Phoenix in Action is an example-based tutorial that teaches you how to use the Phoenix framework to build production-quality web apps. Following a running example of an online auction site, you'll design and build everything from the core components that drive the app to the real-time user interactions where Phoenix really shines. You'll handle business logic, database interactions, and app designs that take advantage of functional programming as you discover a better way to develop web applications. And if you're brand new to Elixir, don't worry! You'll find a Phoenix-oriented tour of the language, along with careful explanations, tips, and coding idioms scattered throughout the example code.

What's inside

  • A complete online auction example developed throughout
  • Database interactions with Ecto
  • Using Channels for real-time communication
  • Functional ideas in a web environment
  • An introduction to the Elixir programming language

About the reader

Written for web developers familiar with a framework like Rails or ASP.NET. No experience of Elixir or Phoenix required.

About the author

Geoffrey Lessel has been a web developer for over 15 years—first with PHP and Perl and now with Ruby on Rails and Phoenix. He has spoken at ElixirConf and blogs about Elixir and Ecto at

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook + liveBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks