# fred-rs
**fred-rs is a simple interface for accessing the Federal Reserve Bank of St. Louis's FRED API.**
---
```toml
[dependencies]
fred_rs = "0.1.1"
```
## Useful Links
[fred-rs Documentation](https://docs.rs/fred-rs/0.1.1)
[FRED API Documentaion](https://research.stlouisfed.org/docs/api/fred/#General_Documentation)
[FRED API Key Information](https://research.stlouisfed.org/docs/api/api_key.html)
U.S. Bureau of Labor Statistics, Unemployment Rate [UNRATE], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/UNRATE, February 20, 2020.
## Usage Below is an example of the general usage for accessing an observation or data series. ```rust use fred_rs::client::FredClient; use fred_rs::series::observation::{Builder, Units, Frequency, Response}; // Create the client object let mut c = match FredClient::new() { Ok(c) => c, Err(msg) => { println!("{}", msg); return }, }; // Create the argument builder let mut builder = Builder::new(); // Set the arguments for the builder builder .observation_start("2000-01-01") .units(Units::PCH) .frequency(Frequency::M); // Make the request and pass in the builder to apply the arguments let resp: Response = match c.series_observation("GNPCA", Some(builder)) { Ok(resp) => resp, Err(msg) => { println!("{}", msg); return }, }; ``` #### Request Parameters All endpoints use the builder approach to construct the API URL. Each builder method corresponds to a paramter that can be added to the API request. In the example above, three parameters are added to the request, observation_start, units and frequency. The [FRED API Documentation](https://research.stlouisfed.org/docs/api/fred/#General_Documentation) explains the possible parameters for each endpoint. Required paramters (except the `tag_names` paramter) are passed to the client function itself. In the example, series_id is a required paramter and is passed directly to the client function as `"GNPCA"`. The `tag_names` parameter available on some endpoints accepts a list of arguments, so it is easier to pass this argument to the builder. ## API Key Developers need to request an API Key in order to access FRED. This can be done at [https://research.stlouisfed.org/docs/api/api_key.html](https://research.stlouisfed.org/docs/api/api_key.html). fred-rs looks for the `FRED_API_KEY` environment variable by default. The variable can be set with the following line in Bash. ```bash export FRED_API_KEY=abcdefghijklmnopqrstuvwxyz123456 ``` Alternatively, the `FredClient.with_key()` function allows the key to be set from a string reference. ```rust use fred_rs::client::FredClient; let mut client = match FredClient::new() { Ok(c) => c, Err(msg) => { println!("{}", msg); return }, }; client.with_key("abcdefghijklmnopqrstuvwxyz123456"); ``` ## Issues/Bugs/Improvments/Help/Questions If you discover any issues or bugs, want to suggest any improvements, or have questions about the crate, feel free to open a GitHub issue or email me directly at matthewdsabo@gmail.com with fred-rs in the subject line. #### License Licensed under either of Apache License, Version 2.0 or MIT license at your option.