Foreword |
|
xi | |
Preface |
|
xiv | |
Acknowledgments |
|
xvi | |
About this book |
|
xviii | |
About the author |
|
xxii | |
About the cover illustration |
|
xxiii | |
Part 1 Getting Started |
|
1 | (66) |
|
|
3 | (14) |
|
|
4 | (1) |
|
1.2 Elixir and Phoenix vs. the alternatives |
|
|
5 | (4) |
|
|
5 | (1) |
|
Efficient, small processes |
|
|
6 | (1) |
|
|
6 | (1) |
|
Minimal hardware requirements, low-cost scaling |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
9 | (4) |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
Macro and metaprogramming support |
|
|
12 | (1) |
|
|
12 | (1) |
|
1.4 Functional vs. object-oriented programming |
|
|
13 | (3) |
|
Overview of functional programming |
|
|
13 | (3) |
|
|
16 | (1) |
|
|
17 | (28) |
|
|
18 | (19) |
|
|
19 | (3) |
|
|
22 | (1) |
|
A small detour into functions |
|
|
23 | (4) |
|
|
27 | (7) |
|
Back to modules and named functions |
|
|
34 | (2) |
|
|
36 | (1) |
|
|
36 | (1) |
|
2.2 Other idiomatic Elixir language features |
|
|
37 | (8) |
|
|
37 | (1) |
|
|
38 | (5) |
|
|
43 | (2) |
|
3 A little Phoenix overview |
|
|
45 | (22) |
|
|
47 | (19) |
|
The basics of a web request |
|
|
47 | (1) |
|
|
48 | (4) |
|
|
52 | (4) |
|
|
56 | (5) |
|
|
61 | (1) |
|
|
62 | (4) |
|
3.2 Putting it all together |
|
|
66 | (1) |
Part 2 Diving In Deep |
|
67 | (172) |
|
4 Phoenix is not your application |
|
|
69 | (17) |
|
4.1 I thought this book was about Phoenix |
|
|
70 | (2) |
|
4.2 The first steps in building your application |
|
|
72 | (12) |
|
|
73 | (2) |
|
|
75 | (4) |
|
|
79 | (2) |
|
Getting an Item based on other information |
|
|
81 | (3) |
|
|
84 | (2) |
|
5 Elixir application structure |
|
|
86 | (21) |
|
5.1 Moving from a single file to an application |
|
|
87 | (8) |
|
Using Mix to create a new application |
|
|
88 | (2) |
|
Generating an auction umbrella application |
|
|
90 | (2) |
|
|
92 | (3) |
|
5.2 Organizing, compiling, and running your new application |
|
|
95 | (5) |
|
Breaking apart the three modules |
|
|
96 | (2) |
|
|
98 | (1) |
|
Running the Auction application for the first time |
|
|
99 | (1) |
|
5.3 Using Hex to get external dependencies |
|
|
100 | (7) |
|
Pulling in your dependencies |
|
|
103 | (4) |
|
|
107 | (12) |
|
6.1 Installing Phoenix on your system |
|
|
108 | (1) |
|
6.2 Creating a new Phoenix application |
|
|
109 | (3) |
|
Running your server for the first time |
|
|
110 | (2) |
|
6.3 Listing items from the fake repo |
|
|
112 | (7) |
|
Modifying the controller and template |
|
|
113 | (6) |
|
7 Being persistent with a database |
|
|
119 | (18) |
|
7.1 A quick intro to Ecto |
|
|
120 | (1) |
|
|
120 | (3) |
|
Using Ecto's Mix tools to set up your database |
|
|
123 | (1) |
|
7.3 Preparing Auction to use the database |
|
|
123 | (7) |
|
Defining the Auction.Item schema |
|
|
123 | (2) |
|
|
125 | (3) |
|
Pointing the public interface to the new repo |
|
|
128 | (1) |
|
Instructing the application to supervise the database connection |
|
|
128 | (1) |
|
|
129 | (1) |
|
7.4 Creating, retrieving, and deleting data in the database |
|
|
130 | (7) |
|
|
131 | (2) |
|
|
133 | (1) |
|
|
134 | (1) |
|
|
135 | (1) |
|
|
135 | (2) |
|
8 Making changes with Ecto.Changeset |
|
|
137 | (15) |
|
8.1 Can't I just ... update? |
|
|
138 | (10) |
|
A brief intro to changesets |
|
|
139 | (1) |
|
Creating a changeset for Auction.Item |
|
|
139 | (9) |
|
|
148 | (4) |
|
Adjusting the public interface for updating |
|
|
150 | (2) |
|
9 Transforming data in your browser |
|
|
152 | (29) |
|
9.1 Handling new routes in your application |
|
|
153 | (7) |
|
|
153 | (4) |
|
|
157 | (1) |
|
|
158 | (1) |
|
|
158 | (2) |
|
9.2 Viewing the details of a single item |
|
|
160 | (5) |
|
Defining the show route and function |
|
|
160 | (2) |
|
Defining the show. html template |
|
|
162 | (1) |
|
Linking to individual items |
|
|
162 | (3) |
|
9.3 Creating items through web forms |
|
|
165 | (9) |
|
Defining the new and create routes |
|
|
165 | (1) |
|
Defining the "new" controller function |
|
|
166 | (1) |
|
Defining the "new" template |
|
|
167 | (1) |
|
Defining the create controller function |
|
|
168 | (6) |
|
9.4 Editing items through web forms |
|
|
174 | (7) |
|
Defining the edit and update routes |
|
|
174 | (1) |
|
Defining the "edit" controller function |
|
|
175 | (1) |
|
Defining the edit.html.eex template |
|
|
176 | (2) |
|
Defining AuctionWeb.ItemController.update/2 |
|
|
178 | (3) |
|
10 Plugs, assigns, and dealing with session data |
|
|
181 | (27) |
|
10.1 Preparing your application for user registration |
|
|
182 | (10) |
|
Defining the Auction. User schema |
|
|
182 | (1) |
|
Creating a migration to create the users table |
|
|
183 | (1) |
|
Defining changesets for Auction. User |
|
|
184 | (3) |
|
Creating API functions in Auction |
|
|
187 | (1) |
|
User registration web flow |
|
|
188 | (4) |
|
10.2 Handling user login and sessions |
|
|
192 | (8) |
|
Creating the route, controller, view, and templates for logging in and out |
|
|
193 | (2) |
|
Implementing the dirty details of sessions and authentication |
|
|
195 | (5) |
|
|
200 | (2) |
|
10.4 Adding site navigation |
|
|
202 | (3) |
|
Implementing the log out function |
|
|
204 | (1) |
|
10.5 Restricting users from certain pages |
|
|
205 | (3) |
|
11 Associating records and accepting bids |
|
|
208 | (31) |
|
|
209 | (1) |
|
11.2 Adding associations to the Auction.Bid schema |
|
|
210 | (12) |
|
A little detour into associations |
|
|
210 | (2) |
|
Creating a migration that describes the associations |
|
|
212 | (5) |
|
Creating a form to accept' bids |
|
|
217 | (5) |
|
11.3 Using has_many with items and users |
|
|
222 | (8) |
|
Preloading and avoiding N+1 queries |
|
|
223 | (3) |
|
Preloading associations in the public interface module and controller |
|
|
226 | (1) |
|
Adding the list of bids to the view template |
|
|
227 | (3) |
|
11.4 Listing a user's bids on their profile page |
|
|
230 | (7) |
|
Using Ecto.Query to construct database queries |
|
|
231 | (1) |
|
Making a view helper function global and using the bids assign |
|
|
232 | (4) |
|
Using Timex to format dates and times |
|
|
236 | (1) |
|
11.5 Some ideas for further improvement |
|
|
237 | (2) |
Part 3 Those Important Extras |
|
239 | (58) |
|
12 Using Phoenix channels for real-time communication |
|
|
241 | (20) |
|
12.1 What are Phoenix channels? |
|
|
242 | (1) |
|
12.2 Connecting a user to a channel and a topic |
|
|
242 | (9) |
|
Handling topic join requests |
|
|
243 | (1) |
|
Getting the user's browser to join a topic |
|
|
244 | (7) |
|
12.3 Sending real-time messages to a user |
|
|
251 | (3) |
|
Receiving messages in the user's browser |
|
|
251 | (1) |
|
Configuring the channel to handle messages |
|
|
252 | (1) |
|
Sending your browser a message from IEx |
|
|
253 | (1) |
|
12.4 Updating all users when a new bid is made |
|
|
254 | (7) |
|
Refactoring the rendering of an item's bids |
|
|
255 | (1) |
|
Modifying the controller to broadcast a message |
|
|
256 | (2) |
|
Handling the broadcasted HTML in the browser |
|
|
258 | (3) |
|
|
261 | (10) |
|
13.1 Scoping API requests to a new controller |
|
|
262 | (2) |
|
13.2 Creating the AuctionWeb.Api.ItemController controller and view |
|
|
264 | (3) |
|
13.3 Including related bid and user data |
|
|
267 | (4) |
|
14 Testing in Elixir and Phoenix |
|
|
271 | (26) |
|
14.1 An introduction to ExUnit |
|
|
272 | (3) |
|
|
273 | (2) |
|
14.2 Setting up tests for Ecto |
|
|
275 | (4) |
|
Configuring a new database |
|
|
275 | (1) |
|
Creating a sandbox and configuring Ecto to use it in tests |
|
|
276 | (1) |
|
Setting up the database before tests run |
|
|
277 | (1) |
|
Creating a Mix alias for use during test runs |
|
|
278 | (1) |
|
14.3 Testing Ecto queries in Auction |
|
|
279 | (4) |
|
Testing Auction.list_items/0 |
|
|
279 | (2) |
|
Testing Auction.get_item/1 |
|
|
281 | (1) |
|
Testing Auction.insert_item/1 |
|
|
282 | (1) |
|
14.4 Simultaneously writing documentation and tests with doctests |
|
|
283 | (8) |
|
Writing function-level documentation |
|
|
283 | (2) |
|
Viewing documentation in IEx |
|
|
285 | (1) |
|
Viewing documentation with ExDoc |
|
|
286 | (1) |
|
Adding examples and doctests |
|
|
287 | (2) |
|
Module-level documentation |
|
|
289 | (2) |
|
14.5 Writing tests For Phoenix |
|
|
291 | (5) |
|
Testing that an item is added to the database on success |
|
|
292 | (1) |
|
Testing that you're redirected to the new item on success |
|
|
293 | (1) |
|
Testing that no item is created on error |
|
|
294 | (1) |
|
Testing that the new item form is rendered on error |
|
|
295 | (1) |
|
The entire ItemControllerTest module |
|
|
295 | (1) |
|
|
296 | (1) |
Appendix A Installing Elixir and Phoenix |
|
297 | (3) |
Appendix B More Elixir resources |
|
300 | (1) |
Index |
|
301 | |