The provided code samples demonstrate how to use the Realtime Register API, where available official SDKs are used as an example. Other examples show how to perform simple GET and POST requests. These examples do not provide a complete implementation of the API. For a complete overview of all available API calls look at the menu on the left. These samples come as-is and are only meant as an example and are not to be used as production code. (I.e.: no error checking)
Demonstration using our official TypeScript SDK
import RealtimeRegisterAPI from '@realtimeregister/api' const rtr = new RealtimeRegisterAPI({ apiKey: 'YOUR_API_KEY', customer: 'YOUR_CUSTOMER_HANDLE' }) // Get TLD metadata rtr.tld.info('nl').then((response) => { console.log(response) //Metadata(hash=..., applicableFor=..., metadata=..., provider=...) console.log(response.metadata) // {....} }).catch((err) => { if (err instanceof AuthenticationError) { console.log('Authentication error') } }) // Check domain rtr.domains.check('testdomain.com').then((response) => { console.log(response) /* { * available: false, * reason: 'test', premium: false, currency: 'USD', price: 3000 * } */ })
Demonstration using our official PHP SDK
<?php use RealtimeRegister\RealtimeRegister; $realtimeRegister = new RealtimeRegister('my-secret-api-key'); $realtimeRegister->contacts->list('johndoe'); $realtimeRegister->tlds->info('nl'); ?>
Class demonstrating REST calls in Python
import requests from typing import List, Dict, Any API_KEY = "..." class RestClient: @staticmethod def do_request(method: str, url: str, **kwargs) -> Dict[Any, Any]: """ Send a request to the Realtime Register API. :param method: Method to use e.g., post or get. :param url: URL to send the request to. :param kwargs: Kwargs to pass to requests.request method. :return: JSON response. """ headers = {"Authorization": f"ApiKey {API_KEY}"} return requests.request(method, "https://api.yoursrs.com/v2/%s" % url, headers=headers, **kwargs).json() def get_domain_names(self) -> List[str]: """ Get a list of domain names. :return: A list of domain names within the current account. """ result = self.do_request("get", "domains") return [ domain.get("domainName") for domain in result["entities"] ] def register_domain(self, domain_name: str, registrant_handle: str, admin_handle: str) -> Dict[Any, Any]: """ Register a domain name with Realtime Register. :param domain_name: Domain name to register. :param registrant_handle: Contact handle of the registrant. :param admin_handle: Contact handle of the admin contact. :return: """ body = { "customer": "test", "period": 12, "registrant": registrant_handle, "contacts": [ {"handle": admin_handle, "role": "ADMIN"}, {"handle": "test", "role": "TECH"}, {"handle": "test", "role": "BILLING"} ] } return self.do_request("post", "domains/" + domain_name, json=body) client = RestClient() client.register_domain("testdomain.com", "registrant", "admin") retval = client.get_domain_names() print(retval)
Class demonstrating REST calls in Java
package com.yoursrs; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; import org.junit.Test; public class RestClient { private String apiKey = "..."; private JSONObject sendRequest(final String resource, final String method, final Map<?, ?> body) throws IOException, InterruptedException { HttpRequest.Builder request = HttpRequest.newBuilder() .uri(URI.create("https://api.yoursrs.com/v2/" + resource)) .header("Content-Type", "application/json; UTF-8") .header("Authorization", "ApiKey " + this.apiKey); if (body != null) { request.method(method, HttpRequest.BodyPublishers.ofString(new JSONObject(body).toString())); } else { request.method(method, HttpRequest.BodyPublishers.noBody()); } HttpResponse<String> response = HttpClient.newHttpClient() .send(request.build(), HttpResponse.BodyHandlers.ofString()); if (response.statusCode() < 200 || response.statusCode() > 299) { throw new IOException("Response code :" + response.statusCode()); } return new JSONObject(new JSONTokener(response.body())); } public void registerDomain(String domainName, String registrant, String admin) throws IOException, InterruptedException { Map<String, Object> body = Map.of( "customer", "test", "period", 12, "registrant", registrant, "contacts", List.of( Map.of("role", "ADMIN", "handle", admin), Map.of("role", "BILLING", "handle", "test"), Map.of("role", "TECH", "handle", "test"))); sendRequest("domains/" + domainName, "POST", body); } public List<String> getDomains() throws IOException, InterruptedException { JSONObject response = sendRequest("domains", "GET", null); JSONArray domains = response.getJSONArray("entities"); return IntStream.range(0, domains.length()) .mapToObj(i -> domains.getJSONObject(i).getString("domainName")) .collect(Collectors.toList()); } @Test public void test() throws IOException, InterruptedException { registerDomain("testdomain.com", "registrant", "admin"); List<String> domains = getDomains(); System.out.println(String.join(", ", domains)); } }