Main Content

fredrs

Create FRED REST connection object

Since R2026a

    Description

    The fredrs function creates an object that represents a connection to the Federal Reserve Economic Data (FRED®) server by using a representational state transfer (REST) API. This programmatic interface allows you to access economic time series data provided by the St. Louis Federal Reserve that is widely used in modeling applications by central banks and educational institutions. After you create a fredrs object, you can retrieve historical time series, such as gross domestic product (GDP), consumer price index (CPI), and various economic rates such as inflation, interest, and exchange rates. The API also enables you to search for time series, retrieve metadata, and query structures such as categories, releases, and tags.

    Creation

    Description

    c = fredrs(APIkey) creates a connection to the FRED REST server that allows you to access data by using an APIKey provided by the St. Louis Federal Reserve. For more information, see the Federal Reserve Bank of St. Louis website.

    example

    c = fredrs(APIkey,timeout,url,mediatype,debugmodevalue) additionally sets the timeout value, the FRED base endpoint URL, the REST API call media type, and the MATLAB® HTTP library debug value for the connection to the FRED server.

    Input Arguments

    expand all

    API authentication token required for connecting to the FRED server, specified as a string scalar or character vector. FRED provides this key for accessing the server.

    Timeout value in seconds for FRED REST API call responses, specified as a positive numeric scalar. This value represents the time before the data server times out and sets the TimeOut property.

    FRED base endpoint URL, specified as a string scalar or character vector. In API documentation, the base endpoint URL is the initial part of the API URL, which provides a shared prefix for all API requests. This argument sets the URL property.

    REST API call media type, specified as a string scalar or character vector. This argument defines the allowed resource structure of the payload exchanged between the client and data server. For more information about media types, see the FRED API documentation. This argument sets the MediaType property.

    MATLAB HTTP library debug mode, specified as 0, 1, or 2. The value of this argument controls the amount of diagnostic information that MATLAB returns about your server connection.

    • 0 returns no diagnostic information.

    • 1 returns partial diagnostic information.

    • 2 returns complete diagnostic information.

    This argument sets the DebugModeValue property.

    Properties

    expand all

    Public

    Timeout value in seconds for FRED REST API call responses. The timeout argument sets this property.

    Hidden

    MATLAB HTTP library debug value. The debugmodevalue argument sets this property.

    REST API call media type. The mediatype argument sets this property.

    FRED base endpoint URL. The url argument sets this property.

    Object Functions

    categoryRetrieve FRED category information
    releaseRetrieve FRED release information
    releasesRetrieve information for all available FRED releases
    seriesRetrieve FRED time series information
    sourceRetrieve FRED source information
    tagsRetrieve FRED tag information

    Examples

    collapse all

    This example assumes that you have obtained your API authentication token from the Federal Reserve Bank of St. Louis website and you stored it in the MATLAB vault by using the setSecret function. Use the fredrs function by specifying APIkey with the getSecret function. Then, display the connection properties.

    APIkey = getSecret("MyAPIkeyFREDRS");
    c = fredrs(APIkey)
    c = 
    
      fredrs with properties:
    
        TimeOut: 200

    Version History

    Introduced in R2026a