Crate zipcodestack

Crate zipcodestack 

Source
Expand description

Idiomatic Rust client for the zipcodestack.com API.

This crate provides a small, async wrapper around the public API at https://zipcodestack.com/. It includes helpers for API status, zip code search, and computing distances between two zip codes.

The client supports authenticating either via apikey: <API_KEY> header or by passing the API key as an apikey query parameter, to match the docs’ guidance that authentication can be done using headers or GET parameters.

Example:

use zipcodestack::{ZipCodeStackClient, AuthMethod, DistanceUnit};

let client = ZipCodeStackClient::builder("YOUR_API_KEY")
    .with_auth_method(AuthMethod::Header)
    .build();

let status = client.status().await?;
println!("API up? {}", status.up.unwrap_or(true));

let search = client.search_zip("90210", Some("US")).await?;
println!("Found: {} {}", search.city.unwrap_or_default(), search.state_code.unwrap_or_default());

let distance = client.distance_between("90210", "10001", Some(DistanceUnit::Miles)).await?;
println!("Distance (mi): {}", distance.distance_miles.unwrap_or_default());

Structs§

ApiErrorPayload
API error payload (if server returns structured error).
DistanceResponse
Distance response between two zip codes.
Quota
Quota details for the authenticated account.
StatusResponse
API status and quota usage response.
ZipCodeStackClient
Async client for the zipcodestack.com API.
ZipCodeStackClientBuilder
Builder to configure a ZipCodeStackClient.
ZipSearchResponse
Zip code search response.

Enums§

AuthMethod
Strategy for authenticating requests.
DistanceUnit
Unit for distance calculations.
ZipCodeStackError
Error type for this crate.