Sample code for 30+ languages & platforms
Rust

ip-api.com IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ip-api.com API.

Chilkat Rust Downloads

Rust

// 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("http://ip-api.com/json/149.250.207.170") 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

// {
//   "as": "AS15854 Hewlett Packard GmbH",
//   "city": "B�blingen",
//   "country": "Germany",
//   "countryCode": "DE",
//   "isp": "Triaton Frankfurt",
//   "lat": 48.6779,
//   "lon": 8.97297,
//   "org": "EntServ Deutschland GmbH",
//   "query": "149.250.207.170",
//   "region": "BW",
//   "regionName": "Baden-W�rttemberg",
//   "status": "success",
//   "timezone": "Europe/Berlin",
//   "zip": "71034"
// }

let as_ = json.string_of("as").unwrap_or_default();
let city = json.string_of("city").unwrap_or_default();
let country = json.string_of("country").unwrap_or_default();
let country_code = json.string_of("countryCode").unwrap_or_default();
let isp = json.string_of("isp").unwrap_or_default();
let lat = json.string_of("lat").unwrap_or_default();
let lon = json.string_of("lon").unwrap_or_default();
let org = json.string_of("org").unwrap_or_default();
let query = json.string_of("query").unwrap_or_default();
let region = json.string_of("region").unwrap_or_default();
let region_name = json.string_of("regionName").unwrap_or_default();
let status = json.string_of("status").unwrap_or_default();
let timezone = json.string_of("timezone").unwrap_or_default();
let zip = json.string_of("zip").unwrap_or_default();