fred_api makes requests to FRED to download
economic data, caching it to a data-store so that repeated requests to FRED can be
avoided. Requires the FRED_API_KEY environment variable to be set. When requests
are made to FRED or the cache, the response is written into the file debug.xml for
convenient debugging.
Requirements
-
FRED_API_KEYenvironment variable has to be set. -
A directory used to cache requests is required. This directory is specified in the
sled::open("../fred_cache/db")function, as shown in the code example below.
A key can be obtained by creating an account at FRED , and should be set as an environment variable like
FRED_API_KEY=abcdefghijklmnopqrstuvwxyz123456
Cargo.toml should have the following dependences,
fred_api = "0.1.4"
sled = "0.34.7"
tokio = "1.44.0"
Code Example
use ;
pub async
Minor Details
Requests are concurrent and there is no rate limit on the requests. Hopefully making use of the cache rather than repeatedly making requests for the same data is sufficient to prevent FRED from blocking excessive requests.
capture_fields() uses regular expressions that assume the data is "well-formed" and
the fields are consistently ordered. I haven't come across any problems in my own
use, but I haven't tried to make these expressions robust in any way. There is always
the option of just taking the bytes as is and doing one's own deserialization (which is
recommended in any case because everyone's reliability/simplicity trade-offs are different).