Introduction
Our digitalized world sets some requirements for businesses’ best practices. One of the most popular and efficient ways to improve your business is with the help of website creation. But there is always a danger when it comes to site settings. The owner has to provide easy-to-remember and unique site addresses. Sometimes, it can be very difficult to monitor free domains (i.e., site names). Even if you’re lucky enough to find an inactive domain, how will you register it? This is where Domainr API can come in handy.
It’s a very useful API, which gives you the ability to search for different domains with multiple filters. It also allows you to check the status of the chosen domain and even go to the registrar. In other words, Domainr API represents a full pipeline of domain maintenance. Let’s create a basic example of the domain registration program with this API.
How to get access to the Domainr API
Basically, you will need to complete two simple steps.
1. Sign Up for a RapidAPI Account
According to the official Domainr docs, you can easily work with all accessible endpoints directly via the RapidAPI interface. The only thing you have to do is to create a developer account on the RapidAPI.
After that, you will be able to subscribe to thousands of different APIs from one central location. So, thanks to this resource, you can not only choose a domain name but also upgrade your site with many additional useful features.
2. Subscribe to the Domainr API.
Find this API via the search bar or go directly to this link.
Here you should provide information about the desired API usage plan. Choose the Pricing tab and click on the only option – Basic.
A little hint for the other APIs – you can choose a plan like this that will provide you with free queries every month if you want to get familiar with a product.
How to use the Domainr API
Now we can jump to the Domainr exploration. Take a look at the left side of the endpoints tab. Here you can see the full list.
As we will need to use all of them, let’s give a brief explanation.
- Search – widely functional endpoint with the ability of intelligent domain search. It supports stemming, query fixing, recommendations, etc. Our program gives you the ability to find the most feasible domains via this endpoint
- Status – here we are able to check current activity and accessibility of the requested domain. The program will help the user has access to a free domain.
- Register – redirection endpoint, which helps to visit a domain market for the chosen option. This is the final station of our program.
Now we can move to the specific endpoint investigation. Choose the Search link and you should see something like this:
Here you can see almost everything needed for comfortable endpoint usage. In this particular case, we can see that the Search endpoint requires 2 header parameters (same as any API at the RapidAPI hub) and 2 request parameters. One from the last group is a mashape-key – your RapidAPI key.
It’s a way to follow all your actions within a system. If you want to get it, you should open your developer apps dashboard and go to the security tab of the application you used.
This page also provides snippets for many different programming languages (including Python), which can be helpful if you have a problem with requests. Finally, you can test some custom requests directly from a browser and track responses.
How to Create a Domain Search App with Python
Our main goal – to create a simple but working example for the domain selection. Let’s use Python 3 as the main programming instrument. So, your machine should have Python > 2.7 installed.You will also need to provide the pip as the installation manager. That’s it, we don’t need anything else!
After that, we can choose a way to work with HTTP requests. In our case, we will use the requests library. Type the next line:
pip install requests
This module has all the important methods for working with an API. And if you have installed it, we can finally create the program file. Let’s say, for example, it will be titled as domain.py. Now we can do all the imports.
import requests import json import webbrowser
Here we add the mentioned requests module and two additional libraries. The json helps to convert the response to the JSON format – it may be helpful in the parsing task. The webbrowser provides a way to open a defined URL in the default browser. We will use it for registering the endpoint.
Now for the next stage – constants creating. We will need a few objects, which should help us in the stable API interaction. Paste the next snippet:
url = "https://domainr.p.rapidapi.com/v2/" mashape = "YOUR_RAPIDAPI_KEY" headers = { 'x-rapidapi-host': "domainr.p.rapidapi.com", 'x-rapidapi-key': "YOUR_RAPIDAPI_KEY" }
Now we need to consider the program structure. Our user will make a domain query. After that, we should process it and send the appropriate request. The user will be able to choose the most suitable one and see its status. And if he/she is satisfied with the results, the program must open the URL of the registrar site.
Add the next functions to the domain.py file:
def represents_int(s): try: int(s) return True except ValueError: return False def search() -> None: query = input('Type query for the domain search: ') while query.strip() == '': print('Query has to be non-empty!') query = input('Type query for the domain search: ') querystring = {"query": query, "mashape-key": mashape} response = json.loads(requests.request("GET", url + 'search', headers=headers, params=querystring).text) domains = [] for domain in response['results']: domains.append(domain['domain']) status(domains)
Here we set the search phase of the program. First of all, we propose to the user an opportunity to write down a query. And if the query isn’t empty, we just send a request to the Search endpoint of the Domainr API. After that, we send the results of it to the status function. Don’t worry, we will create it very soon. Also, pay attention to the represents_int function. Currently, it isn’t used at all, but we will call it the main checker for user answers.
Now we need to do the final job. Paste the next code to our file:
def status(domains: list): text = "Choose one of possible domains:n" for i in range(len(domains)): text += '{0} - {1}n'.format(i+1, domains[i]) text += '0 - returnn' while(True): option = input(text) if (represents_int(option) and (int(option) <= len(domains) and int(option) >= 0)): option = int(option) if option > 0: print('You choose option № {0}'.format(option)) querystring = {"domain": domains[option-1], "mashape-key":mashape} response = json.loads(requests.request("GET", url + 'status', headers=headers, params=querystring).text) print(response) is_user_interested = input('Are you interested in the current domain?n') while (is_user_interested != 'Yes' and is_user_interested != 'No'): print('Type your answer as Yes or No') is_user_interested = input('Are you interested in the current domain?n') if is_user_interested == 'Yes': register_url = requests.request("GET", url + 'register', headers=headers, params=querystring).url webbrowser.open_new_tab(register_url) print('Your are redirected to the registrar website!') else: continue else: search() break else: print('Please, type choose the correct option!')
Here we did all the checkers of possible user behavior. At the first stage, the program asks to choose one proposed domain. As you may remember, we got these propositions from the search() method. Then, the user can point to one of the domains, or return to the previous phase. Pay attention to the fact that we use the already mentioned represents_int method for digits checking here.
If the user picks a specific domain, we make a new request to the Status endpoint. After that, we just return its response. The last stage – to learn more about user interest. If he/she is interested in the chosen domain, we open a new tab in the browser with a market page. If there is no interest, we just return to the domains list.
But right now our program won’t work at all. As we cover all activities in the function declarations, we need visible program calling. Paste the final code lines:
if __name__ == "__main__": search()
All the dirty jobs are done now, and we can finally test our program. Just run the python file with the next terminal command:
python domain.py
Here is the sample listing of our user experience:
$ python domain.py Type query for the domain search: Query has to be non-empty! Type query for the domain search: footbald.com Choose one of possible domains: 1 - footbald.com 2 - footbald.community 3 - footbald.computer 4 - footbald.company 5 - footbald.compare 6 - footbald.net 7 - footbald.org 8 - footbald.de 9 - footbald.com.de 10 - footbald.co.de 0 - return 15 Please, type choose the correct option! Choose one of possible domains: 1 - footbald.com 2 - footbald.community 3 - footbald.computer 4 - footbald.company 5 - footbald.compare 6 - footbald.net 7 - footbald.org 8 - footbald.de 9 - footbald.com.de 10 - footbald.co.de 0 - return 6 You choose option № 6 {'status': [{'domain': 'footbald.net', 'zone': 'net', 'status': 'undelegated inactive', 'summary': 'inactive'}]} Are you interested in the current domain? No Choose one of possible domains: 1 - footbald.com 2 - footbald.community 3 - footbald.computer 4 - footbald.company 5 - footbald.compare 6 - footbald.net 7 - footbald.org 8 - footbald.de 9 - footbald.com.de 10 - footbald.co.de 0 - return 1 You choose option № 1 {'status': [{'domain': 'footbald.com', 'zone': 'com', 'status': 'undelegated inactive', 'summary': 'inactive'}]} Are you interested in the current domain? Yes You are redirected to the registrar website!
And here is the tab, which was opened by our program:
It looks like everything works the way it was supposed to.
Conclusion
An advanced domain search is a very good way to get an excellent domain name. Of course, our application has space to be upgraded. You can try to do this with more intelligent Domainr API usage (e.g., registrar’s filtering, geo zones pointing, etc.) or some other APIs.
But a more important fact is that even with this code, domain pipelines can significantly simplify the search for a domain name in all possible stages.
Leave a Reply