# HolidayAPI Rust client
📆⚙️ [HolidayAPI](https://holidayapi.com/docs) client wrapper for Rust projects.


[](https://wakatime.com/badge/github/guibranco/holiday-api-sdk-rs)
[](https://codeclimate.com/github/guibranco/holiday-api-sdk-rs/maintainability)
[](https://codeclimate.com/github/guibranco/holiday-api-sdk-rs/test_coverage)
[](https://www.codefactor.io/repository/github/guibranco/holiday-api-sdk-rs)
| crates.io | [](https://crates.io/crates/holiday_api) |
Pure Rust bindings to the [Holiday API](https://holidayapi.com).
## Dependencies and support
`holiday_api` is intended to work on all tier 1 supported Rust systems:
- macOS
- Linux
- Windows
## Minimum Compiler Version
`holiday_api` requires `rustc` **1.75** or higher (edition 2021, async/await).
## Getting Started
Add the following to your `Cargo.toml`:
```toml
[dependencies]
holiday_api = "1.0.0"
tokio = { version = "1", features = ["full"] }
```
Then in your `main.rs`:
```rust
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 `.await`ed.
| `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](https://crates.io/crates/dotenv):
```env
HOLIDAYAPI_APIKEY=your_api_key_here
```
```rust
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](https://github.com/guibranco/holiday-api-sdk-rs/blob/main/LICENSE) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT)).