Introduction [ Examples ] Source Code | SourceForge | Maven | Java Documentation (core only) | Caching | Try it | Property Change Notifications | Automated Build Results

Try it

Get acclimated with the FRED Client API using the new Java Web Start Application.

Examples

Below we have several examples that demonstrate how to use the FRED Client. Note that the developer can request data from the FRED web service and then save the result to a database — refer to example 4 below to see how this works.

Example 1

The following example executes a series search — note that all requests to the FRED web services follow the same pattern.

The QueryBuilder takes an instance of the Spring Framework’s RestTemplate and the URL to the FRED endpoint and returns an instance of the class that pertains to that web service.

The QueryBuilder allows the developer to take advantage of method chaining so as to create a single query that includes all of the request parameters; the developer then executes the query by invoking the execute method.

QueryBuilder builder = new QueryBuilder(
    restTemplate,
    "http://api.stlouisfed.org/fred"
);

Seriess seriess = builder
    .series ()
    .search ()
    .setApiKey(API_KEY)
    .setSearchText("money stock")
    .setSearchType(SearchType.fullText)
    .setRealtimeStart(realtimeStart)
    .setRealtimeEnd(realtimeEnd)
    .setLimit(1000)
    .setOffset(1)
    .setOrderBy(OrderBy.searchRank)
    .setSortOrder(SortOrder.desc)
    .setFilterVariable(FilterVariable.frequency)
    .setFilterValue(FilterValue.all)
    .doGet(Seriess.class);

Example 2

The integration tests provide a comprehensive set of examples to assist the developer — see here.

Example 3

An advanced example is available at SourceForge here or you can check out a copy of the project from Subversion using the following command:

svn checkout svn://svn.code.sf.net/p/clfredclient/code/trunk clfredclient-code

Example 4

The FRED Client domain classes have been annotated with Java Persistence API (JPA) annotations so that the developer can make a call to the FRED service and save the result to a database.

The example above can be saved to the database as follows:

    seriessDAO.persist(seriess);

Click here to see an example data access object test.

Click here to see an example of the database schema.