This Spring Boot application provides a web service that retrieves Consumer Price Index (CPI) values and notes for a specified month and year. The service calls the Bureau of Labor Statistics (BLS) API to get the real CPI data and caches the results in an H2 database for subsequent requests. This ensures the application stays within the API call limit.
branch main implemented with H2 in memory db
and branch cache-manager is implemented with Spring [CacheManager](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/CacheManager.html) It is not completed yet!
- Validates input
- Checks if there is a CIS data in the local-cache-db for the given year and month saved in the last 24 hrs
- If there is recent CIS data, it presents that data to the client.
- If there is no recent data, it requests the external BLS-WEB-SERVICE. It then saves the response in the local-cache-db for future reuests. And, also serves the request
Build the JAR file: Open a terminal or command prompt, navigate to the root directory of your project (where the build.gradle file is located), and run:
gradle clean build
This command will compile your code, run tests, and package your application into a JAR file. The JAR file will be located in the build/libs directory by default.
Locate the JAR file: After the build completes, you can find the JAR file in the build/libs directory of your project. It will be named something like your-application-name-version.jar.
Running the JAR File To run the JAR file, use the java -jar command:
java -jar libs/CPI-0.0.1-SNAPSHOT.jar
A pre-built jar can be downloaded here.
You can use the embedded swagger api docs:
http://localhost:8090/swagger-ui/index.html
As port 8080 may be used by most servlet containers, the default port is moved to 8090. You can, however, change the port by updating the value of server.port
in the application.properties
file
server.port=8090
And you can run it
{localhost-or-ip}:{your-port}
If you want to change the port
This sample uses a these open source libs:
Dillinger is currently extended with the following plugins. Instructions on how to use them in your own application are linked below.
Plugin | README |
---|---|
Swagger | Swagger Documentation |
Gradle | Gradle Documentation |
Gson | Gson GitHub |
H2 Database | H2 Database Documentation |
For further reference, please consider the following sections:
- Official Gradle documentation
- Spring Boot Gradle Plugin Reference Guide
- Create an OCI image
- Spring Data JPA
- Rest Repositories
- Spring Web
The following guides illustrate how to use some features concretely:
- Accessing Data with JPA
- Accessing JPA Data with REST
- Accessing Neo4j Data with REST
- Accessing MongoDB Data with REST
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
These additional references should also help you: