Engineering

Checking domain availability in Elixir with the DNSimple API

Javier Acero's profile picture Javier Acero on

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:

  • An Elixir project with the dnsimple library installed.
  • A DNSimple API access token.
  • Your DNSimple account's account_id.

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:

  • domain: The domain name for which availability was checked. This is nothing more than an echo of the parameter you used to make the call.
  • available: Boolean value representing whether the domain is available for registration or not. It will be true if the domain is available to be registered and false if the domain name is already taken.
  • premium: Boolean value representing whether the registry applies special pricing to this domain.

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.

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.