#open-weather #weather #api-request #api-bindings

openweather_sdk

a fully typed SDK for the OpenWeather API

6 releases

0.1.5 Feb 23, 2024
0.1.4 Feb 23, 2024
0.1.3 Oct 17, 2023
0.1.2 May 22, 2023
0.1.1 Apr 28, 2023

#300 in Web programming

Download history 249/week @ 2024-02-19 84/week @ 2024-02-26 1/week @ 2024-03-04 19/week @ 2024-03-11

353 downloads per month

MIT license

73KB
2K SLoC

OpenWeather_SDK

This library is a small rust wrapper for making requests to the OpenWeather API. This library includes:

  • query constructor with full coverage of free-tier API calls
  • type-safe enums for accurate settings
  • type-safe serde deserialization of responses
  • async requests made with the Reqwest library

Query Types Supported

Getting Started

Initialize the library

use openweather_sdk::{OpenWeather, Units, Language};

let openweather = OpenWeather::new(
    "MY_PRIVATE_API_KEY".to_string(),
    Units::Imperial,
    Language::English
);

let lat = 38.795021;
let lon = -77.273300;
let count = 10;

let forecast_response = openweather.forecast.call(lat, lon, count).await;

OneCall Query

let lat = 38.795021;
let lon = -77.273300;
let historical_date = 1606223802;

// get one call data for current weather
let res = openweather.one_call.call(lat, lon).await;

// get one call data for historical weather
let res2 = openweather.one_call.historical(lat, lon, historical_date).await;

// customize response fields
openweather.one_call.fields.minutely = false;
openweather.one_call.fields.hourly = false;
let res3 = openweather.one_call.call(lat, lon).await;

Forecast Query

let lat = 38.795021;
let lon = -77.273300;
let count = 10;

// get forecast data with specified number of timestamps
let res = openweather.forecast.call(lat, lon, count).await;

Current Query

let lat = 38.795021;
let lon = -77.273300;

// get current forecast data
let res = openweather.current.call(lat, lon).await;

Maps Query

let lat = 38.795021;
let lon = -77.273300;
let zoom = 1;
let x_tiles = 1;
let y_tiles = 1;

// get various types of map data
let cloud_map = openweather.maps.get_cloud_map(zoom, x_tiles, y_tiles).await;
let precip_map = openweather.maps.get_precipitation_map(zoom, x_tiles, y_tiles).await;
let temp_map = openweather.maps.get_temperature_map(zoom, x_tiles, y_tiles).await;
let wind_spd_map = openweather.maps.get_wind_speed_map(zoom, x_tiles, y_tiles).await;
let pressure_map = openweather.maps.get_pressure_map(zoom, x_tiles, y_tiles).await;

Air Pollution Query

let lat = 38.795021;
let lon = -77.273300;

// get current and forecast air pollution data
let res = openweather.air_pollution.get_current_air_pollution(lat, lon).await;
let res2 = openweather.air_pollution.get_forecast_air_pollution(lat, lon).await;

// get historical air pollution data with start and end timestamps
let start = 1606223802;
let end = 1606482999;
let res3 = openweather.air_pollution.get_historical_air_pollution(lat, lon, start, end).await;

Geocoding Query

let lat = 38.795021;
let lon = -77.273300;

let city = "Washington";
let state = "DC";
let country = "US";
let limit = 5;

let res = openweather.geocoding.get_geocoding(city, Some(state), Some(country), limit).await;
let res2 = openweather.geocoding.get_geocoding_by_zip_code("20001", None).await;
let res3 = openweather.geocoding.get_location_data(lat, lon, limit).await;

Dependencies

  • reqwest ^0.11
  • tokio ^1.0
  • serde ^1.0.152

License

  • MIT

Contributing

  • Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
  • Please make sure to update tests and documentation as appropriate.

Author

Dependencies

~6–19MB
~284K SLoC