Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Phoenix Web Development
Phoenix Web Development

Phoenix Web Development: Create rich web applications using functional programming techniques with Phoenix and Elixir

Arrow left icon
Profile Icon Brandon Richey
Arrow right icon
€17.99 €26.99
eBook Apr 2018 406 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Brandon Richey
Arrow right icon
€17.99 €26.99
eBook Apr 2018 406 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Phoenix Web Development

Building Controllers, Views, and Templates

This chapter is focused on the building blocks of any Phoenix application. By understanding what controllers, views, and templates are (and how they interact), it becomes much easier to build out our web application. We'll tackle this through the perspective of building the first major component of our Live Voting application, and by writing tests to cover the new functionality introduced.

The reader will become proficient in a lot of the basic tenets of using controllers, views, and templates. In addition, the reader will learn how the three pieces fit together via functional composition. Finally, they'll begin diving into writing their first tests covering controllers and views to start enforcing a strong and real-world systems development life cycle (SDLC). This will be from the perspective of building an actual application...

Understanding the flow of Phoenix connections

When the request comes in, the router takes a look at the incoming connection (referred to in the future as the conn) and determines where this request needs to get routed to. It could be something that needs to be handled in a way appropriate to the browser, a way appropriate for an API to handle, or it could also just plain and simply be a 404 error that needs to get served out (depending on what the router says exists for that particular web application).

From there, the connection is passed along through the router and into a pipeline of plugs. Plugs are constructs that can be reduced down to functions that take in the connection structure and optionally some options, and then apply some form of transformation (if appropriate) and return out a modified connection structure. The beauty of this idea is in its simplicity; each plug...

Creating our Social Voting project

What we haven't done yet is actually create our Phoenix project, so let's do that! I'm going to call this application "Vocial" ("Social Voting" because I am incredibly creative)! We'll start off by running our mix task to create a Phoenix application:

$ mix phx.new vocial
* creating vocial/config/config.exs
* creating vocial/config/dev.exs
* creating vocial/config/prod.exs
* creating vocial/config/prod.secret.exs
* creating vocial/config/test.exs
* creating vocial/lib/vocial/application.ex
* creating vocial/lib/vocial.ex
* creating vocial/lib/vocial_web/channels/user_socket.ex
* creating vocial/lib/vocial_web/views/error_helpers.ex
* creating vocial/lib/vocial_web/views/error_view.ex
* creating vocial/lib/vocial_web/endpoint.ex
* creating vocial/lib/vocial_web/router.ex
* creating vocial/lib/vocial_web.ex
* creating...

Creating a poll controller

If we want to start building out our web application, we'll need to start with some of the base structures that are used to receive our incoming connection, make decisions, pull in new data, and reformat/structure out the response to the user. We'll start with the most fundamental of these: the controllers. Our controllers act as the glue between our templates, our database, and the incoming/outgoing connections; they put everything together in a way that the end user's browser or client can understand. To understand how to effectively use controllers, however, we'll need to ensure we understand how controllers are structured and how best to use them!

Understanding the controller's structure

...

Writing controller tests

We'll want to have some good tests covering all of the code that we will be writing in the course of this application, since we're all good software engineers and should follow good software engineering processes! We'll start off with our controller tests, which include a few cool tools to simulate making connection requests to various controller actions and inspecting the output of the controller functions.

Understanding the code behind tests

When we start off creating our own controllers/views/etc, if we're not using a generator, we won't have any new logic or functionality to cover tests for the new code we’re writing. Due to this, if we just run mix test without...

Summary

We’re now at a point where we have a good baseline to work from for our Poll Controller, which means we're also at a point where we can start transitioning from here into the work for our data side of things. In the next chapter, we’ll start diving into Contexts and Schemas and try to get a good working understanding of integrating a data model into our Phoenix application (and a lot of the design decisions that influence the current structure and why those decisions were made)!

So, now that we know how to glue together the different parts of our application and we understand a few of the pieces that are getting assembled, we need to explore what is arguably one of the largest and more complex pieces of the request/response puzzle: the database! We'll take a deep dive into Ecto and, of course, write good tests to cover any new code we write!

...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • •Build a strong foundation in Functional-Programming techniques while learning to build compelling web applications
  • •Understand the Elixir Concurrency and parallelization model to build high-performing blazingly fast applications
  • •Learn to test, debug and deploy your web applications using Phoenix framework

Description

Phoenix is a modern web development framework that is used to build API’s and web applications. It is built on Elixir and runs on Erlang VM which makes it much faster than other options. With Elixir and Phoenix, you build your application the right way, ready to scale and ready for the increasing demands of real-time web applications. This book covers the basics of the Phoenix web framework, showing you how to build a community voting application, and is divided into three parts. In the first part, you will be introduced to Phoenix and Elixir and understand the core terminologies that are used to describe them. You will also learn to build controller pages, store and retrieve data, add users to your app pages and protect your database. In the second section you will be able to reinforce your knowledge of architecting real time applications in phoenix and not only debug these applications but also diagnose issues in them. In the third and final section you will have the complete understanding of deploying and running the phoenix application and should be comfortable to make your first application release By the end of this book, you'll have a strong grasp of all of the core fundamentals of the Phoenix framework, and will have built a full production-ready web application from scratch.

Who is this book for?

This book is for people with a basic knowledge of Elixir, who want to start building web applications. Prior experience with web technologies is assumed.

What you will learn

  • •Learn Phoenix Framework fundamentals and v1.3 s new application structure
  • •Build real-time applications with channels and presence
  • •Utilize GenServers and other OTP fundamentals to keep an application stable
  • •Track users as they sign in and out of chat with Phoenix's built-in presence functionality
  • •Write your own database interaction code that is safe, bug-free, and easy to work with
  • •Explore testing and debugging methodologies to understand a real software development lifecycle for a Phoenix application
  • •Deploy and run your Phoenix application in production

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2018
Length: 406 pages
Edition : 1st
Language : English
ISBN-13 : 9781787284777
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Apr 30, 2018
Length: 406 pages
Edition : 1st
Language : English
ISBN-13 : 9781787284777
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 99.97
Learning Elixir
€29.99
Mastering Elixir
€36.99
Phoenix Web Development
€32.99
Total 99.97 Stars icon

Table of Contents

13 Chapters
A Brief Introduction to Elixir and Phoenix Chevron down icon Chevron up icon
Building Controllers, Views, and Templates Chevron down icon Chevron up icon
Storing and Retrieving Vote Data with Ecto Pages Chevron down icon Chevron up icon
Introducing User Accounts and Sessions Chevron down icon Chevron up icon
Validations, Errors, and Tying Loose Ends Chevron down icon Chevron up icon
Live Voting with Phoenix Chevron down icon Chevron up icon
Improving Our Application and Adding Features Chevron down icon Chevron up icon
Adding Chat to Your Phoenix Application Chevron down icon Chevron up icon
Using Presence and ETS in Phoenix Chevron down icon Chevron up icon
Working with Elixir's Concurrency Model Chevron down icon Chevron up icon
Implementing OAuth in Our Application Chevron down icon Chevron up icon
Building an API and Deploying Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.