Web development with Elixir
Last updated
Last updated
Web development has become a growing area that Elixir has begun to shine. This is in part thanks to the created by that has made web development very hassle free with Elixir.
Phoenix is a server-side framework designed for building web applications with Elixir. It was first created by Chris McCord and modeled after the framework.
It is a server-side framework, which means that all of the computation is performed on the server and sent to the client to render. Phoenix implements the Model-View-Controller (MVC) pattern:
This guide will provide an introduction to Phoenix by getting you to build a to-do list application with some basic data persistence using SQLite3 (we are using a local database to reduce the amount of setup required to following along).
This guide will cover both base Phoenix and Phoenix LiveView. The reason for covering base Phoenix is to provide a firm foundation on the terminology before discussing slightly more advanced concepts in LiveView.
The following is the content structure of this guide:
Directory structure of Phoenix projects
Request lifecycle
Representing to-do items in Elixir
Anatomy of routers
Creating a new HTTP endpoint
Rendering the to-do list
Introduction to LiveView
Adding more actions to to-do list
Persisting data with Ecto and SQLite3
To get started with using web development using Elixir and Phoenix, we will start by installing the Phoenix CLI archive on your machine:
Then, you can create a new Phoenix project with the necessary boilerplate:
You may be prompted on whether you want to fetch the dependencies, agree to that option.
Then, navigate to the new folder:
Then, create the database. Phoenix uses a very popular Elixir library, Ecto for performing database queries and mapping:
Finally, you can run the demo application:
You can build both your frontend and backend with Phoenix. The frontend of Phoenix is written as .heex
files which is Phoenix's template language that embeds Elixir into HTML. The backend of Phoenix uses .
As mentioned in the beginning of the guide, this guide does not attempt to provide a comprehensive introduction to the Phoenix framework. There are many nuances to how Phoenix can be used and you should refer to the official documentation if you are .
You should see the following show up at
If you want to view the full codebase without running each command, refer to