Get acclimated with the FRED Client API using the new demonstration application.
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.
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, "https://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);
The integration tests provide a comprehensive set of examples to assist the developer — see here.
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
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: