Need help? Call Live Support at +31 (0) 38 453 07 59

The provided code samples demonstrate how to build a GET and a POST request and send it to Realtime Register. They 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)

APIExample.php

Class demonstrating REST calls in PHP

<?php

class RestClient {
    var $conn_handle;

    private function do_request($method, $uri, $json=NULL) {
        if (!isset($conn_handle)) {
            $this->conn_handle = curl_init();
        }

        $options = array(
            CURLOPT_URL => "http://server/v2/" . $uri,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_POSTFIELDS => $json,
            CURLOPT_HTTPAUTH => CURLAUTH_ANY,
            CURLOPT_USERPWD => "test/admin:password",
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($json)
            )
        );

        curl_setopt_array($this->conn_handle, $options);

        return json_decode(curl_exec($this->conn_handle), 1);
    }

    public function get_domains() {
        return $this->do_request("GET", "domains/");
    }

    public function register_domain($domain_name, $registrant, $admin) {
        $body = array(
            'customer' => 'test',
            'period' => 12,
            'registrant' => $registrant,
            'contacts' => array(
               array('handle' => $admin, 'role' => 'ADMIN'),
               array('handle' => 'test', 'role' => 'BILLING'),
               array('handle' => 'test', 'role' => 'TECH'),
            )
        );
        return $this->do_request("POST", "domains/" . $domain_name, json_encode($body));
    }
}

$client = new RestClient;
print_r($client->register_domain("myrefsdtestdomain23.com", "registrant", "registrant"));
print_r($client->get_domains());
?>

APIExample.py

Class demonstrating REST calls in Python

from base64 import b64encode
from httplib import HTTPConnection
import json


class RestClient(object):
    client = None
    base_url = "/v2/"

    def do_request(self, method, uri, body=None):
        self.client = HTTPConnection("server")
        user_pass = b64encode(b"test/admin:password").decode("ascii")

        request_kwargs = {
            'method': method,
            'url': self.base_url + uri,
            'headers': {'Authorization': 'Basic %s' % user_pass, 'Content-Type': 'application/json'},
            'body': body
        }

        self.client.request(**request_kwargs)
        api_response = self.client.getresponse()

        return api_response.read()

    def get_domains(self):
        result = json.loads(self.do_request('GET', 'domains'))

        list_domains = []

        for domain in result['entities']:
            list_domains.append(domain['domainName'])

        return list_domains

    def register_domain(self, domain_name, registrant, admin):
        body = {
            "customer": "test",
            "period": 12,
            "registrant": registrant,
            "contacts": [
                {"handle": admin, "role": "ADMIN"},
                {"handle": "test", "role": "TECH"},
                {"handle": "test", "role": "BILLING"}
            ]
        }
        result = self.do_request('POST', 'domains/' + domain_name, json.dumps(body))
        return result

client = RestClient()
client.register_domain("myrefsdtestdomain23.com", "registrant", "registrant")
retval = client.get_domains()
print retval
APIExample.java

Class demonstrating REST calls in Java

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.UriBuilder;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.google.gson.JsonParser;

public class RestClient {
    WebResource service;
    Gson gson;

    public RestClient() {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        HTTPBasicAuthFilter filter = new HTTPBasicAuthFilter("test/admin", "password");
        client.addFilter(filter);
        service = client.resource(getBaseURI());

        gson = new Gson();
    }

    public void registerDomain(String domainName, String registrant, String admin) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("customer", "test");
        map.put("period", 12);
        map.put("registrant", registrant);
        Collection<HashMap<String, String>> contactMap = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> contactAdmin = new HashMap<String, String>();
        HashMap<String, String> contactBilling = new HashMap<String, String>();
        HashMap<String, String> contactTech = new HashMap<String, String>();
        contactAdmin.put("handle", admin);
        contactAdmin.put("role", "ADMIN");
        contactBilling.put("handle", "test");
        contactBilling.put("role", "BILLING");
        contactTech.put("handle", "test");
        contactTech.put("role", "TECH");
        contactMap.add(contactAdmin);
        contactMap.add(contactBilling);
        contactMap.add(contactTech);

        map.put("contacts", contactMap);

        String json = gson.toJson(map);
        service.path("domains").path(domainName).header("Content-Type", "application/json").post(json);
    }

    public String getDomains() {
        String out = service.path("domains").get(String.class);

        String outDomains = "";

        JsonParser parser = new JsonParser();
        JsonArray domainList = parser.parse(out).getAsJsonObject().getAsJsonArray("entities");
        for (JsonElement element : domainList) {
            outDomains += "<tr><td>" + element.getAsJsonObject().get("domainName").getAsString() + "</td></tr>";
        }
        return outDomains;
    }

    private static URI getBaseURI() {
        return UriBuilder.fromUri("http://server/v2").build();
    }
}