DNSimple platform

The platform

Add-ons: getting started

Add-Ons: Reference

Getting started: Elixir and Phoenix

This tutorial covers how to get the Phoenix “Hello Domains” app ready and running on your machine.

Make sure to have followed the previous steps, which are common to all languages and technologies.

Installing Elixir and Phoenix

Since this is the Phoenix “Hello Domains” application you will need to have Elixir installed. The official documentation of the language will do a pretty good job at guiding you through the necessary steps for installation.

Once you have Elixir running, you will have to make sure to have all the required Phoenix dependencies installed too (you may want to take a look at the Phonix installation guide). Even though it has Node.js as an optional dependency, you will need it for the “Hello Domains” application, make sure to install it before continuing.

Getting the code

The first step is to clone the repo with the Hello Domains in Phoenix application:

> git clone git@github.com:dnsimple/hello-domains-phoenix.git

Cloning into 'hello-domains-phoenix'...
remote: Counting objects: 141, done.
remote: Total 141 (delta 0), reused 0 (delta 0), pack-reused 141
Receiving objects: 100% (141/141), 62.54 KiB | 0 bytes/s, done.
Resolving deltas: 100% (36/36), done.

Having completed this, you have the application source code on your machine. Feel free to take some time and browse through it.

Installing Node.js packages

Next install all the Node.js related dependencies by running npm install:

> npm install

├─┬ babel-brunch@6.0.6
│ ├─┬ anymatch@1.3.0
│ │ ├── arrify@1.0.1
│ │ └─┬ micromatch@2.3.11
│ │   ├─┬ arr-diff@2.0.0
│ │   │ └── arr-flatten@1.0.1
└─┬ uglify-js-brunch@2.0.1
  └─┬ uglify-js@2.6.4
    ├── async@0.2.10
    ├── uglify-to-browserify@1.0.2
    └─┬ yargs@3.10.0
      ├── camelcase@1.2.1
      ├─┬ cliui@2.1.0
      │ ├─┬ center-align@0.1.3
      │ │ ├─┬ align-text@0.1.4
      │ │ │ └── longest@1.0.1
      │ │ └── lazy-cache@1.0.4
      │ ├── right-align@0.1.3
      │ └── wordwrap@0.0.2
      ├── decamelize@1.2.0
      └── window-size@0.1.0

Configuring the DNSimple API client

Now you will have to create a dev.secret.exs file in the config directory. Configure the DNSimple API client there as follows:

use Mix.Config

config :hello_domains,
  dnsimple_client_id: "client_id",
  dnsimple_client_secret: "client_secret"

Replace client_id and client_secret with the corresponding values for the OAuth application you created earlier.

If you decided to use dnsimple.com to follow this guide, open config/config.exs and update dnsimple_client_base_url as follows:

# Configures the DNSimple environment to target
config :hello_domains,
  dnsimple_client_base_url: "https://api.dnsimple.com"

Getting the dependencies

Now install all the necessary dependencies for Phoenix and the “Hello Domains” application. One of them will be the DNSimple Elixir API Client:

To install the dependencies run mix deps.get:

> mix deps.get

Running dependency resolution
* Getting phoenix (Hex package)
  Checking package (https://repo.hex.pm/tarballs/phoenix-1.2.1.tar)
  Using locally cached package
* Getting dnsimple (Hex package)
  Checking package (https://repo.hex.pm/tarballs/dnsimple-1.0.0.tar)
  Using locally cached package
* Getting poolboy (Hex package)
  Checking package (https://repo.hex.pm/tarballs/poolboy-1.5.1.tar)
  Using locally cached package

Note that if you you try to get the dependencies before creating the config/dev.secret.exs file for the OAuth Settings you will get an error:

> mix deps.get

** (Mix.Config.LoadError) could not load config config/dev.secret.exs
    ** (Code.LoadError) could not load /Users/jacegu/Dev/dnsimple/hellodomains/phoenix/config/dev.secret.exs
    (elixir) lib/code.ex:657: Code.find_file/2
    (stdlib) erl_eval.erl:404: :erl_eval.expr/5

Creating the database

Last step before having Hello Domains running: creating the database and loading the schema.

Please make sure to have PostgreSQL running before continuing. You will see references to Ecto in the following commands, for now all you need to know is that Ecto is the library that Phoenix uses to interact with the database. You can read more about it in the Phoenix framework documentation.

To create the database run mix ecto.create. Mix will compile the application before creating the database if you hadn’t compiled it already.

> mix ecto.create

The database for HelloDomains.Repo has been created

Now load the schema by running mix ecto.migrate

> mix ecto.migrate

17:01:51.022 [info]  == Running HelloDomains.Repo.Migrations.CreateAccounts.change/0 forward

17:01:51.022 [info]  create table accounts

17:01:51.058 [info]  create index accounts_dnsimple_account_id_index

17:01:51.063 [info]  == Migrated in 0.0s

The table and indexes to store DNSimple account information have been created.

Running the application

Congratulations for reaching to this point! You are almost done, the final step is booting up the “Hello Domains” application by running mix phoenix.server:

> mix phoenix.server
[info] Running HelloDomains.Endpoint with Cowboy using http://localhost:4000
02 Jan 17:14:06 - info: compiled 6 files into 2 files, copied 2 in 1.5 sec

The application will be running on localhost:4000.