Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An async client for the FRED API.

Cheap to clone — the underlying reqwest::Client holds a connection pool behind an Arc, so clones share it.

Implementations§

Source§

impl Client

Source

pub fn new(api_key: impl Into<String>) -> Result<Self>

Build a client with the given FRED API key.

§Errors

Returns an error if the underlying HTTP client cannot be built.

Source

pub fn from_env() -> Result<Self>

Build a client, reading the API key from the FRED_API_KEY environment variable.

§Errors

Returns Error::InvalidInput if FRED_API_KEY is unset, or an error if the underlying HTTP client cannot be built.

Source

pub fn observations(&self, series_id: &SeriesId) -> ObservationsRequest<'_>

Begin an observations request for a series.

Returns a builder; set optional parameters (date range, units transform, frequency aggregation, sort order, paging) and call ObservationsRequest::send to run it. With nothing set, FRED’s defaults apply (full history, levels, ascending by date).

use ferric_fred::{SeriesId, Units};
let obs = client
    .observations(&SeriesId::new("GNPCA"))
    .units(Units::PercentChange)
    .limit(10)
    .send()
    .await?;
Source

pub async fn series(&self, series_id: &SeriesId) -> Result<Series>

Fetch metadata for a series (the fred/series endpoint).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn search(&self, search_text: impl Into<String>) -> SeriesSearchRequest<'_>

Begin a search over series (the fred/series/search endpoint).

Returns a builder; set optional parameters (search type, ordering, sort, paging) and call SeriesSearchRequest::send to run it.

use ferric_fred::OrderBy;
let results = client
    .search("industrial production")
    .order_by(OrderBy::Popularity)
    .limit(5)
    .send()
    .await?;
println!("{} matches", results.count);
Source

pub fn series_search_tags( &self, search_text: impl Into<String>, ) -> TagsRequest<'_>

Begin a request for the tags on the series matching a search (the fred/series/search/tags endpoint) — the tag facets of a full-text search, for narrowing it down.

Returns a TagsRequest builder; set optional tag-filter text (sent as FRED’s tag_search_text), sort, and paging, then call send to run it.

let results = client.series_search_tags("unemployment").limit(10).send().await?;
println!("{} tags", results.count);

Begin a request for the tags that co-occur, among the series matching a search, with a seed set of tags (the fred/series/search/related_tags endpoint).

Accepts any iterable of seed tag names (joined with ; for FRED). Returns a TagsRequest builder; set optional tag-filter text (sent as tag_search_text), sort, and paging, then call send to run it.

let results = client
    .series_search_related_tags("unemployment", ["monthly"])
    .send()
    .await?;
println!("{} related tags", results.count);
Source

pub async fn category(&self, category_id: CategoryId) -> Result<Category>

Fetch a single category by id (the fred/category endpoint). Use CategoryId::ROOT for the top of the tree.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub async fn category_children( &self, category_id: CategoryId, ) -> Result<Vec<Category>>

Fetch the child categories of a category (the fred/category/children endpoint) — the primary way to walk the category tree downward.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Fetch the categories related to a category (the fred/category/related endpoint) — cross-links to sibling topics elsewhere in the tree, distinct from the parent/child hierarchy. FRED returns the full list unpaginated, so this yields a plain Vec<Category> (often empty).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn category_series(&self, category_id: CategoryId) -> SeriesListRequest<'_>

Begin a request for the series in a category (the fred/category/series endpoint).

Returns a SeriesListRequest builder; set optional ordering/paging and call send to run it.

use ferric_fred::CategoryId;
let results = client
    .category_series(CategoryId::new(125))
    .limit(5)
    .send()
    .await?;
println!("{} series", results.count);
Source

pub fn category_tags(&self, category_id: CategoryId) -> TagsRequest<'_>

Begin a request for the tags used by the series in a category (the fred/category/tags endpoint) — the tag facets available when browsing a category.

Returns a TagsRequest builder; set optional tag-filter text/sort/ paging and call send to run it.

use ferric_fred::CategoryId;
let results = client.category_tags(CategoryId::new(125)).limit(10).send().await?;
println!("{} tags", results.count);

Begin a request for the tags that co-occur, within a category, with a seed set of tags (the fred/category/related_tags endpoint) — refine a category browse by discovering adjacent tags.

Accepts any iterable of seed tag names (joined with ; for FRED). Returns a TagsRequest builder; set optional tag-filter text/sort/ paging and call send to run it.

use ferric_fred::CategoryId;
let results = client.category_related_tags(CategoryId::new(125), ["gdp"]).send().await?;
println!("{} related tags", results.count);
Source

pub fn releases(&self) -> ReleasesRequest<'_>

Begin a request listing all FRED data releases (the fred/releases endpoint) — a browse axis parallel to categories.

Returns a builder; set optional sort/paging and call ReleasesRequest::send to run it.

let results = client.releases().limit(20).send().await?;
println!("{} releases", results.count);
Source

pub fn releases_dates(&self) -> ReleaseDatesRequest<'_>

Begin a request for the publication dates of all releases (the fred/releases/dates endpoint) — a release calendar across FRED, newest first by default.

Returns a builder; set optional sort/paging (and include_dates_with_no_data) and call ReleaseDatesRequest::send to run it.

let calendar = client.releases_dates().limit(20).send().await?;
println!("{} release dates", calendar.count);
Source

pub async fn release(&self, release_id: ReleaseId) -> Result<Release>

Fetch a single release by id (the fred/release endpoint).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn release_series(&self, release_id: ReleaseId) -> SeriesListRequest<'_>

Begin a request for the series in a release (the fred/release/series endpoint).

Returns a SeriesListRequest builder; set optional ordering/paging and call send to run it.

use ferric_fred::ReleaseId;
let results = client
    .release_series(ReleaseId::new(53))
    .limit(5)
    .send()
    .await?;
println!("{} series", results.count);
Source

pub async fn release_sources( &self, release_id: ReleaseId, ) -> Result<Vec<Source>>

Fetch the sources for a release (the fred/release/sources endpoint) — the reverse of source_releases. FRED returns the full list unpaginated, so this yields a plain Vec<Source>.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn release_dates(&self, release_id: ReleaseId) -> ReleaseDatesRequest<'_>

Begin a request for the publication dates of one release (the fred/release/dates endpoint) — that release’s calendar, oldest first by default.

Returns a ReleaseDatesRequest builder; set optional sort/paging (and include_dates_with_no_data) and call send to run it.

use ferric_fred::ReleaseId;
let dates = client.release_dates(ReleaseId::new(82)).limit(10).send().await?;
println!("{} release dates", dates.count);
Source

pub fn release_tables(&self, release_id: ReleaseId) -> ReleaseTablesRequest<'_>

Begin a request for a release’s table tree (the fred/release/tables endpoint) — the nested layout (sections, tables, and series rows) a release uses to present its series.

Returns a builder; optionally scope to a subtree with element, then call ReleaseTablesRequest::send to run it.

use ferric_fred::ReleaseId;
let table = client.release_tables(ReleaseId::new(10)).send().await?;
println!("{} root elements", table.roots.len());
Source

pub fn release_tags(&self, release_id: ReleaseId) -> TagsRequest<'_>

Begin a request for the tags used by the series in a release (the fred/release/tags endpoint) — the tag facets available when browsing a release.

Returns a TagsRequest builder; set optional tag-filter text/sort/ paging and call send to run it.

use ferric_fred::ReleaseId;
let results = client.release_tags(ReleaseId::new(53)).limit(10).send().await?;
println!("{} tags", results.count);

Begin a request for the tags that co-occur, within a release, with a seed set of tags (the fred/release/related_tags endpoint).

Accepts any iterable of seed tag names (joined with ; for FRED). Returns a TagsRequest builder; set optional tag-filter text/sort/ paging and call send to run it.

use ferric_fred::ReleaseId;
let results = client.release_related_tags(ReleaseId::new(53), ["gdp"]).send().await?;
println!("{} related tags", results.count);
Source

pub fn tags(&self) -> TagsRequest<'_>

Begin a request to browse or search FRED’s tag vocabulary (the fred/tags endpoint).

Returns a builder; set optional search text/sort/paging and call TagsRequest::send to run it.

let results = client.tags().search_text("gdp").limit(10).send().await?;
println!("{} tags", results.count);
Source

pub fn related_tags<I, S>(&self, tag_names: I) -> TagsRequest<'_>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Begin a request for the tags that co-occur with a seed set of tags (the fred/related_tags endpoint) — refine a faceted search by discovering adjacent tags.

Accepts any iterable of tag names (they are joined with ; for FRED). Returns a TagsRequest builder; set optional search text/sort/paging and call send to run it.

let results = client.related_tags(["gdp"]).limit(10).send().await?;
println!("{} tags related to gdp", results.count);
Source

pub fn tags_series<I, S>(&self, tag_names: I) -> SeriesListRequest<'_>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Begin a request for the series carrying all of the given tags (the fred/tags/series endpoint) — faceted discovery.

Accepts any iterable of tag names (they are joined with ; for FRED). Returns a SeriesListRequest builder; set optional ordering/paging and call send to run it.

let results = client.tags_series(["gdp", "quarterly"]).limit(5).send().await?;
println!("{} series", results.count);
Source

pub async fn series_tags(&self, series_id: &SeriesId) -> Result<TagsResults>

Fetch the tags attached to a series (the fred/series/tags endpoint) — the reverse of tags_series.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn series_updates(&self) -> SeriesUpdatesRequest<'_>

Begin a request for the most recently updated series (the fred/series/updates endpoint) — a “what changed” feed, ordered by last-updated time.

Returns a builder; set an optional class filter/paging and call SeriesUpdatesRequest::send to run it.

let results = client.series_updates().limit(20).send().await?;
println!("{} recently updated", results.count);
Source

pub fn series_vintagedates( &self, series_id: &SeriesId, ) -> VintageDatesRequest<'_>

Begin a request for a series’ vintage dates (the fred/series/vintagedates endpoint) — the dates on which the series was revised or newly released.

Returns a builder; set optional sort/paging and call VintageDatesRequest::send to run it.

use ferric_fred::SeriesId;
let dates = client
    .series_vintagedates(&SeriesId::new("GNPCA"))
    .limit(10)
    .send()
    .await?;
println!("{} vintage dates", dates.count);
Source

pub async fn series_categories( &self, series_id: &SeriesId, ) -> Result<Vec<Category>>

Fetch the categories a series belongs to (the fred/series/categories endpoint) — the reverse of category_series.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub async fn series_release(&self, series_id: &SeriesId) -> Result<Release>

Fetch the release a series belongs to (the fred/series/release endpoint) — the reverse of release_series.

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn sources(&self) -> SourcesRequest<'_>

Begin a request listing all FRED data sources (the fred/sources endpoint) — the organizations that produce releases.

Returns a builder; set optional sort/paging and call SourcesRequest::send to run it.

let results = client.sources().limit(20).send().await?;
println!("{} sources", results.count);
Source

pub async fn source(&self, source_id: SourceId) -> Result<Source>

Fetch a single source by id (the fred/source endpoint).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn source_releases(&self, source_id: SourceId) -> ReleasesRequest<'_>

Begin a request for the releases produced by a source (the fred/source/releases endpoint).

Returns a ReleasesRequest builder; set optional sort/paging and call send to run it.

use ferric_fred::SourceId;
let results = client.source_releases(SourceId::new(18)).limit(5).send().await?;
println!("{} releases", results.count);
Source

pub async fn regional_data( &self, series_group: &SeriesGroupId, region_type: RegionType, date: NaiveDate, units: impl Into<String>, frequency: Frequency, season: SeasonalAdjustment, ) -> Result<RegionalData>

Fetch a region cross-section for a series group (the GeoFRED geofred/regional/data endpoint) — the value in every region of region_type on date, for the given units label, frequency, and season.

FRED requires all of these parameters (a live probe rejects any omission — ADR-0025), so this is a direct call rather than a builder. units is a free-form measurement label FRED echoes into the result title (e.g. "Dollars"), not a transformation code.

use ferric_fred::{Frequency, RegionType, SeasonalAdjustment, SeriesGroupId};
let date = chrono::NaiveDate::from_ymd_opt(2013, 1, 1).unwrap();
let data = client
    .regional_data(
        &SeriesGroupId::new("882"),
        RegionType::State,
        date,
        "Dollars",
        Frequency::Annual,
        SeasonalAdjustment::NotSeasonallyAdjusted,
    )
    .await?;
println!("{}", data.meta.title);
§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub fn series_data(&self, series_id: &SeriesId) -> SeriesDataRequest<'_>

Begin a request for one regional series’ values across regions (the GeoFRED geofred/series/data endpoint).

Returns a builder; set an optional date or start_date and call send. With neither set, FRED returns the most recent date.

use ferric_fred::SeriesId;
let data = client
    .series_data(&SeriesId::new("SMU56000000500000001"))
    .send()
    .await?;
println!("{} dates", data.meta.data.len());
Source

pub async fn series_group(&self, series_id: &SeriesId) -> Result<SeriesGroup>

Fetch the series-group metadata for a regional series (the GeoFRED geofred/series/group endpoint) — pass a regional series_id and get back the group it belongs to (title, region type, date span).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Source

pub async fn shape_file(&self, shape: ShapeType) -> Result<ShapeFile>

Fetch the region boundary polygons for a shape type (the GeoFRED geofred/shapes/file endpoint) — a GeoJSON ShapeFile this crate transports without interpreting (ADR-0025).

§Errors

Returns an error if the request fails to send, FRED returns a non-success status, or the response body cannot be deserialized.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more