Code Monkey home page Code Monkey logo

acme's Introduction

Introducing Phoenix - ElixirConf US 2017 Training Application

Course Description

Phoenix is an Elixir web framework for building scalable web services for the modern web. In this training, we’ll take a guided tour of the framework, going from the very basics, to building our own realtime application.

You’ll see the framework’s foundations, core components, and learn how to use Phoenix to write powerful web services.

We’ll start by exploring the foundations of the framework in Elixir’s Plug library, followed by the core components of Phoenix’s Router and Controller layers.

Next, we’ll review the View layer and build an application together as we learn each concept.

We’ll finish by using the PubSub layer to add realtime functionality to our application.

Along the way, attendees will see how to apply advanced features like router pipelines and plug middelware and receive tips on how to structure a Phoenix application for real-world services.

Prerequisites

This course is designed for people who have prior experience with other web frameworks and want to learn how to get started with Phoenix.

I will not assume that you have any prior experience with Elixir in this course. So if you are a beginner, have no fear. The course format encourages open-dialog and learning by asking questions along the way.

In order to ensure that we get started in a timely manner. Please make sure to get all the dependencies (outlined below) installed prior to the training.

Please take a look at this list and make sure to install anything necessary for your system. Having dependencies installed in advance will allow us to hit the ground running and cover the most material possible.

Installing dependencies

Elixir

Phoenix is written in Elixir, and our application code will also be written in Elixir. We won't get far in a Phoenix app without it! The Elixir site maintains a great Installation Page to help.

We need Elixir 1.4 or higher for this course.

If we have just installed Elixir for the first time, we will need to install the Hex package manager and Rebar as well. Hex is necessary to get a Phoenix app running (by installing dependencies) and to install any extra dependencies we might need along the way. Rebar is a similar tool used by many existing Erlang projects that we may depend on.

Here's the command to install Hex and Rebar:

$ mix local.hex
$ mix local.rebar

If you are not yet familiar with Elixir, I recommend taking a look at the excellent Getting Started guide.

Erlang

Elixir code compiles to Erlang byte code to run on the Erlang virtual machine. Without Erlang, Elixir code has no virtual machine to run on, so we need to install Erlang as well.

When we install Elixir using instructions from the Elixir Installation Page, we will usually get Erlang too. If Erlang was not installed along with Elixir, please see the Erlang Instructions section of the Elixir Installation Page for instructions.

Node.js (>= 5.0)

Phoenix will use brunch.io to compile static assets (javascript, css, etc), by default. Brunch.io uses the node package manager (npm) to install its dependencies, and npm requires node.js.

We can get node.js from the download page. When selecting a package to download, it's important to note that Phoenix requires version 5.0 or greater.

Mac OS X users can also install node.js via homebrew.

Debian/Ubuntu users might see an error that looks like this:

sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"

This is due to Debian having conflicting binaries for node: discussion on stackoverflow

There are two options to fix this problem, either:

  • install nodejs-legacy:
$ apt-get install nodejs-legacy

or

  • create a symlink
$ ln -s /usr/bin/nodejs /usr/bin/node

PostgreSQL

We will be interacting with a database while building our application. Phoenix uses the database abstraction library Ecto which supports a number of databases.

For this course, we'll be using PostgreSQL for consistency across attendees.

The PostgreSQL wiki has installation guides for a number of different systems.

Optional configuration

By default, Phoenix expects to connect to the database with user of postgres having a password of postgres. If this is not the case for your PostgreSQL installation, you can change this in config/dev.exs like so:

# Configure your database
config :workshop, Workshop.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "<change-me>",
  password: "<change-me>",
  database: "workshop_dev",
  hostname: "localhost",
  pool_size: 10

Some installations (installing via homebrew or using Postgres.app) will use your username with no password.

inotify-tools (for linux users)

This is a Linux-only filesystem watcher that Phoenix uses for live code reloading. (Mac OS X or Windows users can safely ignore it.)

Linux users need to install this dependency. Please consult the inotify-tools wiki for distribution-specific installation instructions.

Building this application

Now that we have all the dependencies installed, let's clone, build, compile, and start it up!

If you haven't already, clone this repo and change into the directory of your choosing:

$ git clone https://github.com/scrogson/acme
$ cd acme

Next, we'll need to fetch our Elixir dependencies:

$ mix deps.get

Create the database for our application:

$ mix ecto.create

If you see this error:

FATAL (invalid_authorization_specification): role "postgres" does
not exist

You will need to update your username and password in config/dev.exs as explained above in Optional configuration.

If you installed Postgres with homebrew, you can alternatively add the postgres user like so:

$(brew --prefix postgresql)/bin/createuser -s postgres

Install the nodejs dependencies:

$ cd assets
$ npm install

We are all set! Now it's time to start the application:

$ mix phx.server

You can also run your app inside IEx (Interactive Elixir) with:

$ iex -S mix phx.server

Now you can visit localhost:4000 from your browser and see your new Phoenix app running. Yay!

Other dependencies

We will be using an elixir package which requires a C compiler such as gcc and make to be installed on you system.

Ubuntu and Debian-based systems can get gcc and make by installing build-essential package. Also erlang-dev may be needed if not included in your Erlang/OTP version.

Having trouble?

It is vital that we get all the setup dealt with prior to the workshop so that we can focus on learning as much as possible with the limited time. Please feel free to contact me directly if you have any trouble with getting anything setup.

acme's People

Contributors

scrogson avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.