Function send_request

Source
pub async fn send_request(
    req_spec: &RequestSpec,
    req: Request<Body>,
    cache: bool,
    fred: bool,
    db: &Db,
) -> Result<Vec<u8>, String>
Expand description

Send a request, specifying if the request should go to the cache first, and if the request should go to FRED. Successful requests to FRED are always cached.

use fred_api::{build_request, send_request};

let db: sled::Db = sled::open("../fred_cache/db").unwrap();
let (req_spec, req) = build_request("series/observations?series_id=CPGRLE01AUQ657N").unwrap();
// request to cache is `true`
// request to FRED is `false`
let bytes = send_request(&req_spec, req, true, false, &db).await.unwrap();