Zig Requires Chilkat v11.0.0+
Zig
RDAP Domain Lookup using rdap.org
See more HTTP Misc Examples
Demonstrates doing an RDAP domain lookup using the rdap.org public RDAP server.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Send HTTP requests to https://rdap.org/<type>/<object>, where <type> is the object type (one of domain, ip, autnum, entity etc)
// and <object> is the object identifier (eg example.com, 192.168.0.1, 64496, etc).
// For example, here's a lookup for "oracle.com"
const sb_response = try chilkat.StringBuilder.init();
defer sb_response.deinit();
http.quickGetSb("https://rdap.org/domain/oracle.com", sb_response) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const status_code = http.getLastStatus();
if (status_code != 200) {
std.debug.print("Error response:\n", .{});
std.debug.print("{s}\n", .{try sb_response.getAsString(alloc)});
std.debug.print("status code: {d}\n", .{status_code});
return;
}
// Load the JSON response and examine..
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadSb(sb_response) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Here's a sample response, and the parsing code generated from the above online tool follows..
// {
// "objectClassName": "domain",
// "handle": "607513_DOMAIN_COM-VRSN",
// "ldhName": "ORACLE.COM",
// "links": [
// {
// "value": "https:\/\/rdap.verisign.com\/com\/v1\/domain\/ORACLE.COM",
// "rel": "self",
// "href": "https:\/\/rdap.verisign.com\/com\/v1\/domain\/ORACLE.COM",
// "type": "application\/rdap+json"
// },
// {
// "value": "https:\/\/rdap.markmonitor.com\/rdap\/domain\/ORACLE.COM",
// "rel": "related",
// "href": "https:\/\/rdap.markmonitor.com\/rdap\/domain\/ORACLE.COM",
// "type": "application\/rdap+json"
// }
// ],
// "status": [
// "client delete prohibited",
// "client transfer prohibited",
// "client update prohibited",
// "server delete prohibited",
// "server transfer prohibited",
// "server update prohibited"
// ],
// "entities": [
// {
// "objectClassName": "entity",
// "handle": "292",
// "roles": [
// "registrar"
// ],
// "publicIds": [
// {
// "type": "IANA Registrar ID",
// "identifier": "292"
// }
// ],
// "vcardArray": [
// "vcard",
// [
// [
// "version",
// {},
// "text",
// "4.0"
// ],
// [
// "fn",
// {},
// "text",
// "MarkMonitor Inc."
// ]
// ]
// ],
// "entities": [
// {
// "objectClassName": "entity",
// "roles": [
// "abuse"
// ],
// "vcardArray": [
// "vcard",
// [
// [
// "version",
// {},
// "text",
// "4.0"
// ],
// [
// "fn",
// {},
// "text",
// ""
// ],
// [
// "tel",
// {
// "type": "voice"
// },
// "uri",
// "tel:+1.2086851750"
// ],
// [
// "email",
// {},
// "text",
// "abusecomplaints@markmonitor.com"
// ]
// ]
// ]
// }
// ]
// }
// ],
// "events": [
// {
// "eventAction": "registration",
// "eventDate": "1988-12-02T05:00:00Z"
// },
// {
// "eventAction": "expiration",
// "eventDate": "2025-12-01T05:00:00Z"
// },
// {
// "eventAction": "last changed",
// "eventDate": "2024-10-30T09:32:52Z"
// },
// {
// "eventAction": "last update of RDAP database",
// "eventDate": "2024-11-26T14:11:14Z"
// }
// ],
// "secureDNS": {
// "delegationSigned": false
// },
// "nameservers": [
// {
// "objectClassName": "nameserver",
// "ldhName": "A1-160.AKAM.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "A11-66.AKAM.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "A13-65.AKAM.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "A18-67.AKAM.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "NS1.P201.DNS.ORACLECLOUD.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "NS2.P201.DNS.ORACLECLOUD.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "NS3.P201.DNS.ORACLECLOUD.NET"
// },
// {
// "objectClassName": "nameserver",
// "ldhName": "NS4.P201.DNS.ORACLECLOUD.NET"
// }
// ],
// "rdapConformance": [
// "rdap_level_0",
// "icann_rdap_technical_implementation_guide_0",
// "icann_rdap_response_profile_0"
// ],
// "notices": [
// {
// "title": "Terms of Use",
// "description": [
// "Service subject to Terms of Use."
// ],
// "links": [
// {
// "href": "https:\/\/www.verisign.com\/domain-names\/registration-data-access-protocol\/terms-service\/index.xhtml",
// "type": "text\/html"
// }
// ]
// },
// {
// "title": "Status Codes",
// "description": [
// "For more information on domain status codes, please visit https:\/\/icann.org\/epp"
// ],
// "links": [
// {
// "href": "https:\/\/icann.org\/epp",
// "type": "text\/html"
// }
// ]
// },
// {
// "title": "RDDS Inaccuracy Complaint Form",
// "description": [
// "URL of the ICANN RDDS Inaccuracy Complaint Form: https:\/\/icann.org\/wicf"
// ],
// "links": [
// {
// "href": "https:\/\/icann.org\/wicf",
// "type": "text\/html"
// }
// ]
// }
// ]
// }
var value: [:0]const u8 = "";
var rel: [:0]const u8 = "";
var href: [:0]const u8 = "";
var v_type: [:0]const u8 = "";
var str_val: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
var identifier: [:0]const u8 = "";
var k: i32 = 0;
var count_k: i32 = 0;
const json1 = try chilkat.JsonObject.init();
defer json1.deinit();
var i1_: i32 = 0;
var count_i1: i32 = 0;
var j1: i32 = 0;
var count_j1: i32 = 0;
var event_action: [:0]const u8 = "";
var event_date: [:0]const u8 = "";
var title: [:0]const u8 = "";
var object_class_name: [:0]const u8 = try json.stringOf(alloc, "objectClassName");
var handle: [:0]const u8 = try json.stringOf(alloc, "handle");
var ldh_name: [:0]const u8 = try json.stringOf(alloc, "ldhName");
_ = json.boolOf("secureDNS.delegationSigned");
var i: i32 = 0;
var count_i: i32 = json.sizeOfArray("links");
while (i < count_i) {
json.setI(i);
value = try json.stringOf(alloc, "links[i].value");
rel = try json.stringOf(alloc, "links[i].rel");
href = try json.stringOf(alloc, "links[i].href");
v_type = try json.stringOf(alloc, "links[i].type");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("status");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "status[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("entities");
while (i < count_i) {
json.setI(i);
object_class_name = try json.stringOf(alloc, "entities[i].objectClassName");
handle = try json.stringOf(alloc, "entities[i].handle");
j = 0;
count_j = json.sizeOfArray("entities[i].roles");
while (j < count_j) {
json.setJ(j);
str_val = try json.stringOf(alloc, "entities[i].roles[j]");
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("entities[i].publicIds");
while (j < count_j) {
json.setJ(j);
v_type = try json.stringOf(alloc, "entities[i].publicIds[j].type");
identifier = try json.stringOf(alloc, "entities[i].publicIds[j].identifier");
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("entities[i].vcardArray");
while (j < count_j) {
json.setJ(j);
str_val = try json.stringOf(alloc, "entities[i].vcardArray[j]");
k = 0;
count_k = json.sizeOfArray("entities[i].vcardArray[j]");
while (k < count_k) {
json.setK(k);
json.objectOf2("entities[i].vcardArray[j][k]", json1) catch {};
i1_ = 0;
count_i1 = json1.sizeOfArray("");
while (i1_ < count_i1) {
json1.setI(i1_);
str_val = try json1.stringOf(alloc, "[i]");
i1_ = i1_ + 1;
}
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("entities[i].entities");
while (j < count_j) {
json.setJ(j);
object_class_name = try json.stringOf(alloc, "entities[i].entities[j].objectClassName");
k = 0;
count_k = json.sizeOfArray("entities[i].entities[j].roles");
while (k < count_k) {
json.setK(k);
str_val = try json.stringOf(alloc, "entities[i].entities[j].roles[k]");
k = k + 1;
}
k = 0;
count_k = json.sizeOfArray("entities[i].entities[j].vcardArray");
while (k < count_k) {
json.setK(k);
str_val = try json.stringOf(alloc, "entities[i].entities[j].vcardArray[k]");
json.objectOf2("entities[i].entities[j].vcardArray[k]", json1) catch {};
i1_ = 0;
count_i1 = json1.sizeOfArray("");
while (i1_ < count_i1) {
json1.setI(i1_);
j1 = 0;
count_j1 = json1.sizeOfArray("[i]");
while (j1 < count_j1) {
json1.setJ(j1);
str_val = try json1.stringOf(alloc, "[i][j]");
j1 = j1 + 1;
}
i1_ = i1_ + 1;
}
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("events");
while (i < count_i) {
json.setI(i);
event_action = try json.stringOf(alloc, "events[i].eventAction");
event_date = try json.stringOf(alloc, "events[i].eventDate");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("nameservers");
while (i < count_i) {
json.setI(i);
object_class_name = try json.stringOf(alloc, "nameservers[i].objectClassName");
ldh_name = try json.stringOf(alloc, "nameservers[i].ldhName");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("rdapConformance");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "rdapConformance[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("notices");
while (i < count_i) {
json.setI(i);
title = try json.stringOf(alloc, "notices[i].title");
j = 0;
count_j = json.sizeOfArray("notices[i].description");
while (j < count_j) {
json.setJ(j);
str_val = try json.stringOf(alloc, "notices[i].description[j]");
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("notices[i].links");
while (j < count_j) {
json.setJ(j);
href = try json.stringOf(alloc, "notices[i].links[j].href");
v_type = try json.stringOf(alloc, "notices[i].links[j].type");
j = j + 1;
}
i = i + 1;
}
}