Crate worldtimeapi
source · [−]Expand description
World Time Wrapper
This is a simple wrapper for the World Time API.
Usage
To use this crate, add worldtimeapi to your Cargo.toml:
[dependencies]
worldtimeapi = "0.1"Then create a client for an endpoint (currently they only offer “ip” and “timezone”):
use std::collections::HashMap;
use worldtimeapi::service::Client;
#[tokio::main]
async fn main() {
let client = Client::new("timezone").await;
let mut payload = HashMap::new();
payload.insert("area", "America");
payload.insert("location", "New_York");
let result = client.get(payload).await.unwrap();
println!("{}", result.datetime());
}To get a list of regions and locations, use the regions method:
use worldtimeapi::service::Client;
#[tokio::main]
async fn main() {
let client = Client::new("timezone").await;
let regions = client.regions();
println!("{:?}", regions);
} Modules
A collection of JSON responses from the World Time API.
The client for the World Time API.