Table of Contents
Acknowledgments ix
Preface xiii
1 Introducing Phoenix 1
Productive 2
Concurrent 4
Beautiful Code 8
Interactive 10
Reliable 13
Part I Building with Functional MVC
2 The Lay of the Land 17
Simple Functions 17
Installing Your Development Environment 20
Creating a Throwaway Project 22
Building a Feature 23
Going Deeper: The Request Pipeline 30
Wrapping Up 38
3 Controllers 41
Understanding Controllers 41
Building a Controller 49
Coding Views 50
Using Helpers 52
Showing a User 54
Wrapping Up 58
4 Ecto and Changesets 59
Understanding Ecto 59
Defining the User Schema and Migration 60
Using the Repository to Add Data 63
Building Forms 66
Creating Resources 70
Wrapping Up 75
5 Authenticating Users 77
Preparing for Authentication 77
Managing Registration Changesets 79
Creating Users 82
The Anatomy of a Plug 85
Writing an Authentication Plug 88
Implementing Login and Logout 93
Presenting User Account Links 97
Wrapping Up 100
6 Generators and Relationships 101
Using Generators 101
Building Relationships 110
Managing Related Data 113
In-context Relationships 117
Wrapping Up 122
7 Ecto Queries and Constraints 123
Seeding and Associating Categories 123
Diving Deeper into Ecto Queries 130
Constraints 136
Wrapping Up 143
8 Testing MVC 145
Understanding ExUnit 146
Testing Contexts 150
Using Ecto Sandbox for Test Isolation and Concurrency 157
Integration Tests 158
Unit-Testing Plugs 167
Testing Views and Templates 172
Wrapping Up 174
Part II Writing Interactive and Maintainable Applications
9 Watching Videos 177
Watching Videos 177
Adding JavaScript 181
Creating Slugs 186
Wrapping Up 192
10 Using Channels 193
The Channel 194
Phoenix Clients with ES6 195
Preparing Our Server for the Channel 198
Creating the Channel 200
Sending and Receiving Events 202
Socket Authentication 207
Persisting Annotations 210
Handling Disconnects 217
Tracking Presence on a Channel 220
Wrapping Up 226
11 Observer and Umbrellas 229
Introspecting Applications with Observer 230
Using Umbrellas 233
Extracting Rumbl and RumblWeb 236
Wrapping Up 241
12 OTP 243
Managing State with Processes 243
Building GenServers for OTP 247
Designing an Information System with OTP 257
Building the Wolfram Info System 265
Integrating OTP Services with Channels 274
Wrapping Up 277
13 Testing Channels and OTP 279
Testing the Information System 280
Isolating Wolfram 285
Adding Tests to Channels 289
Authenticating a Test Socket 290
Communicating with a Test Channel 291
Wrapping Up 296
14 What's Next? 297
Other Interesting Features 298
Phoenix LiveView 302
Phoenix PubSub 2.0 313
Phoenix and Telemetry Integration 314
Good Luck! 316
Index 317