Lessons learned from buying, connecting, and operating domains
Free Trial
Engineering

Checking domain availability in Elixir with the DNSimple API

Javier Acero's profile picture Javier Acero

Following the release of version 2 of the DNSimple API we have started providing different resources to help developers become proficient with it. One of these resources is a guide on how to get started with the DNSimple API in Elixir.

Building on top of that blog post, I want to show you how easy it is to check if a domain name is available for registration using our domain management API.

Requirements

In order to follow this tutorial you will need:

If you are missing any of these, please read the getting started blog post, as it covers how to get each of them.

Checking domain availability

When you have the project ready, as well as your access token and your account id, checking the availability of a domain is as simple as calling the Registrar.check_domain/4 function. This function calls the check endpoint of the DNSimple API.

Start a new IEx session by typing iex -S mix and do the following (be sure to replace TOKEN with your access token, and ACCOUNT_ID with your real account id):

iex(1)> client = %Dnsimple.Client{access_token: "TOKEN", base_url: "https://api.sandbox.dnsimple.com"}
iex(2)> {:ok, response} = Dnsimple.Registrar.check_domain(client, "ACCOUNT_ID", "elixir-lang.org")

As you can see, this function follows the same convention as the whoami function: it returns a tuple with the result of the call and the response struct.

Now let's take a look at the data that was returned in the response.

iex(3)> response.data
%Dnsimple.DomainCheck{available: false, domain: "elixir-lang.org",
 premium: false}

The returned data is a Dnsimple.DomainCheck struct. It has 3 separate fields:

That is all you needed to know to check if a domain name is available from Elixir. Easy, right?

With this knowledge you can easily create a tool to check domain names from the command line, or even your favourite chat bot (although if you use Slack we have already done that for you).

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.