Crate brightsky

Crate brightsky 

Source
Expand description

§BrightSky - German Weather Data API Client

This crate provides type-safe query builders and response types for the Bright Sky API, a free and open-source weather API that serves weather data from Germany’s meteorological service (DWD).

§Design Philosophy

This crate focuses on query building and response types only. You bring your own HTTP client (reqwest, reqwless, ureq, etc.).

§Features

  • Current Weather: Get real-time weather conditions from SYNOP observations
  • Historical & Forecast Weather: Access hourly weather records and forecasts
  • Radar Data: Retrieve precipitation radar with 1km spatial resolution
  • Weather Alerts: Access official weather warnings from DWD
  • No API Key Required: The public API at https://api.brightsky.dev/ is free
  • no_std Compatible: Works in embedded environments

§Quick Start (with reqwest)

use brightsky::{CurrentWeatherQueryBuilder, ToBrightSkyUrl, types::CurrentWeatherResponse};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build the query
    let query = CurrentWeatherQueryBuilder::new()
        .with_lat_lon((52.52, 13.4))  // Berlin
        .build()?;

    // Generate URL and fetch with your HTTP client
    let url = query.to_url("https://api.brightsky.dev")?;
    let response: CurrentWeatherResponse = reqwest::get(url).await?.json().await?;

    println!("Temperature: {:?}°C", response.weather.temperature);
    Ok(())
}

§Embedded Usage (no_std with reqwless)

use brightsky::{CurrentWeatherQueryBuilder, ToBrightSkyUrl, types::CurrentWeatherResponse};

let query = CurrentWeatherQueryBuilder::new()
    .with_lat_lon((52.52, 13.4))
    .build()?;

// Generate URL string for embedded HTTP clients
let url = query.to_url_string("https://api.brightsky.dev")?;

// Use your HTTP client to fetch, then deserialize
let response: CurrentWeatherResponse = serde_json::from_slice(&body)?;

§Feature Flags

  • std (default): Enable std library support and url::Url generation
  • reqwest: Enable BrightSkyReqwestExt trait for ergonomic reqwest usage
  • Without std: Only string URL generation available (no_std compatible)

§With reqwest Extension Trait

Enable the reqwest feature for the most ergonomic API:

use brightsky::{CurrentWeatherQueryBuilder, ext::BrightSkyReqwestExt, types::CurrentWeatherResponse};

let client = reqwest::Client::new();
let query = CurrentWeatherQueryBuilder::new()
    .with_lat_lon((52.52, 13.4))
    .build()?;

let response: CurrentWeatherResponse = client.get_brightsky(query).await?;

Modules§

types
Type definitions for Bright Sky API responses and parameters.

Structs§

AlertsQueryBuilder
Query builder for the alerts endpoint (/alerts).
CurrentWeatherQueryBuilder
Query builder for the current weather endpoint (/current_weather).
RadarWeatherQueryBuilder
Query builder for the radar endpoint (/radar).
WeatherQueryBuilder
Query builder for the weather endpoint (/weather).

Enums§

BrightSkyError
Error type for Bright Sky query building operations.

Constants§

BRIGHT_SKY_API
Base URL for the Bright Sky API

Traits§

ToBrightSkyClientUrlDeprecated
ToBrightSkyUrl
Trait for converting query builders into Bright Sky API URLs.