Rust
Rust
ipapi.co IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipapi.co REST API.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
let Ok(json_str) = http.quick_get_str("https://ipapi.co/149.250.207.170/json") else {
println!("{}", http.last_error_text());
return;
};
let json = chilkat::JsonObject::new();
json.set_emit_compact(false);
let _ = json.load(&json_str).is_ok();
println!("{}", json.emit().unwrap_or_default());
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "ip": "149.250.207.170",
// "city": "B�blingen",
// "region": "Baden-W�rttemberg",
// "region_code": null,
// "country": "DE",
// "country_name": "Germany",
// "continent_code": "EU",
// "in_eu": true,
// "postal": null,
// "latitude": null,
// "longitude": null,
// "timezone": null,
// "utc_offset": null,
// "country_calling_code": "+49",
// "currency": "EUR",
// "languages": "de",
// "asn": "AS15854",
// "org": "EntServ Deutschland GmbH"
// }
let ip = json.string_of("ip").unwrap_or_default();
let city = json.string_of("city").unwrap_or_default();
let region = json.string_of("region").unwrap_or_default();
let region_code = json.string_of("region_code").unwrap_or_default();
let country = json.string_of("country").unwrap_or_default();
let country_name = json.string_of("country_name").unwrap_or_default();
let continent_code = json.string_of("continent_code").unwrap_or_default();
let in_eu = json.bool_of("in_eu");
let postal = json.string_of("postal").unwrap_or_default();
let latitude = json.string_of("latitude").unwrap_or_default();
let longitude = json.string_of("longitude").unwrap_or_default();
let timezone = json.string_of("timezone").unwrap_or_default();
let utc_offset = json.string_of("utc_offset").unwrap_or_default();
let country_calling_code = json.string_of("country_calling_code").unwrap_or_default();
let currency = json.string_of("currency").unwrap_or_default();
let languages = json.string_of("languages").unwrap_or_default();
let asn = json.string_of("asn").unwrap_or_default();
let org = json.string_of("org").unwrap_or_default();