HolidayAPI Rust client

Logo

The HolidayAPI client for Rust projects.

View the Project on GitHub guibranco/holiday-api-sdk-rs

HolidayAPI Rust client

📆⚙️ HolidayAPI client wrapper for Rust projects.

GitHub last commit (branch) wakatime

Maintainability Test Coverage CodeFactor

Service Status
crates.io Crates.io

Pure Rust bindings to the Holiday API.

Dependencies and support

holiday_api is intended to work on all tier 1 supported Rust systems:

Minimum Compiler Version

holiday_api requires rustc 1.75 or higher (edition 2021, async/await).

Getting Started

Add the following to your Cargo.toml:

[dependencies]
holiday_api = "1.0.0"
tokio = { version = "1", features = ["full"] }

Then in your main.rs:

use holiday_api::HolidayAPIClient;

#[tokio::main]
async fn main() {
    let client = HolidayAPIClient::new("YOUR_HOLIDAY_API_KEY".to_string());

    match client.search_holidays("2019", "BR").await {
        Err(e) => eprintln!("{:?}", e),
        Ok(Some(holidays)) => {
            for holiday in holidays {
                println!(
                    "Holiday: {} | Date: {} | Country: {}",
                    holiday.name, holiday.date, holiday.country
                );
            }
        }
        Ok(None) => println!("No holidays found."),
    }
}

Available methods

All methods are async and must be .awaited.

Method Description
search_holidays(year, country) Returns holidays for a given year and country code
search_countries() Returns a list of all supported countries
search_languages() Returns a list of all supported languages
workday(country, start, days) Returns the workday date after N working days from a start date
workdays(country, start, end) Returns the number of working days between two dates

Environment variable

The API key can be loaded from a .env file using dotenv:

HOLIDAYAPI_APIKEY=your_api_key_here
use dotenv::dotenv;
use std::env;

dotenv().ok();
let api_key = env::var("HOLIDAYAPI_APIKEY").unwrap();
let client = HolidayAPIClient::new(api_key);

License

Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).