Features

Announcing Elixir API client

Javier Acero's profile picture Javier Acero on

At DNSimple we have been super excited about Elixir programming language for quite some time. Several months ago we started building some internal tools using Elixir and we couldn't be happier with it. Our excitement has grown so much that, not only are we now sponsoring the Madrid Elixir meetup, we also decided to provide an official client for our new API.

The DNSimple API v2 Elixir client is now available on Hex, you can start using it today in your own projects.

Do you want to register a domain from your Phoenix app? Now it's possible. Do you want to create or update your DNS records from your OTP application? You can do that too.

Getting started

The first thing you will need in order to play with our API is authentication. You can choose one of the supported methods. If you want to go the OAuth dance route, the client has some helpers to make your life easier.

You can use the authorize_url function to generate the URL to start the dance:

state     = "some-random-state"
client_id = "a1b2c3d4e5"

client = %Dnsimple.Client{base_url: "https://api.sandbox.dnsimple.com"}
Dnsimple.Oauth.authorize_url(client, client_id, state: state)
# => https://sandbox.dnsimple.com/oauth/authorize?client_id=a1b2c3d4e5&state=some-random-state&response_type=code

And to obtain the access token:

code          = "0123456789" # the code from the callback
state         = "some-random-state"
client_id     = "a1b2c3d4e5"
client_secret = "the-app-secret"

{:ok, res} = Dnsimple.Oauth.exchange_authorization_for_token(client, %{
  code: code,
  client_id: client_id,
  client_secret: client_secret,
  state: state
})
auth = res.data

Once you have the token you can start using the endpoints that require authentication:

client = %Dnsimple.Client{access_token: access_token, base_url: "https://api.sandbox.dnsimple.com"}
{:ok, response} = Dnsimple.Identity.whoami(client)

If you want to register a domain from your Elixir application, you only have to do the following:

Dnsimple.Registrar.register(client, account_id, "example.com", %{registrant_id: registrant_id})

Where the registrant_id is the id of one of the contacts in your DNSimple account. Needless to say you can manage the contacts using the client too.

Once registered, adding a record to your new domain is as simple as:

Dnsimple.Zones.create_record(client, account_id, "example.com", %{name: "", type: "ALIAS", content: "myapp.herokuapp.com", ttl: 600})

As you can see, writing an Elixir application that manages your domains and DNS is super easy.

The DNSimple API client is now available on Hex, the standard Elixir package manager. You can download and start using it today. Here are more examples that you may want to take a look at. If you want to experiment, we also provide a Sandbox environment where you can create a free account and play with our API client yourself.

Future plans

2016 has been the year of the API at DNSimple. We have been working super hard on version 2 and the official clients for it. We even ate our own dog food and built some cool tools on top of it.

However the Go and Ruby clients are almost feature complete while the Elixir one still needs some love. That's why we will be drinking huge amounts of potion in the next few weeks to bring it up to speed and support all the features that our API provides.

Stay tuned!

Share on Twitter and Facebook

Javier Acero's profile picture

Javier Acero

Programmer. Minimalist. Apple fanboy. Currently having fun at DNSimple. I love coffee and my cat.

We think domain management should be easy.
That's why we continue building DNSimple.

Try us free for 30 days
4.5 stars

4.3 out of 5 stars.

Based on Trustpilot.com and G2.com reviews.