Expand description
The client (based on ip-api.com API) allows you to get information about the IP address
§Example
use ip_api_client as Client;
use ip_api_client::{IpApiLanguage, IpData};
// You can
// `generate_empty_config` (to create your own config from scratch)
// `generate_minimum_config` (that includes only important fields)
// `generate_maximum_config` (that includes all fields)
let ip_data: IpData = Client::generate_empty_config()
// or `exclude_country` if this field is already included
// in the generated config
.include_country()
// or `exclude_currency` if this field is already included in
// the generated config
.include_currency()
// available languages: de/en (default)/es/fr/ja/pt-Br/ru/zh-CN
.set_language(IpApiLanguage::De)
// `make_request` takes
// "ip"/"domain"/"empty string (if you want to request your ip)"
.make_request("1.1.1.1")
.await
.unwrap();
println!(
"{}'s national currency is {}",
ip_data.country.unwrap(),
ip_data.currency.unwrap(),
);
// If you want to request more than one ip, you can use `make_batch_request`
let ip_batch_data: Vec<IpData> = Client::generate_empty_config()
.include_isp()
// `make_batch_request` takes "IPv4"/"IPv6"
.make_batch_request(vec!["1.1.1.1", "8.8.8.8"])
.await
.unwrap();
println!(
"1.1.1.1 belongs to `{}` and 8.8.8.8 belongs to `{}`",
ip_batch_data.get(0).unwrap().isp.as_ref().unwrap(),
ip_batch_data.get(1).unwrap().isp.as_ref().unwrap(),
);
Structs§
- IpApi
Config - Configuration structure allows you to customize the requested fields in the request to save traffic
- IpData
- The data that will be received after the making a request
Enums§
- IpApi
Error - Represents all the ways that a request can fail
- IpApi
Language - Represents all available languages for
IpData
Functions§
- generate_
empty_ config - Create an empty config to create your own from scratch
- generate_
maximum_ config - Generate maximum config that includes all fields
- generate_
minimum_ config - Generate minimum config that includes only important fields