HTTP Quote Client
Build a Java command-line program that fetches a random quote from a public web API and prints it nicely, for example: "The only way to do great work is to love what you do." — Steve Jobs. If the internet is down or the API fails, it shows the last quote it fetched successfully, which it saves to a local file, along with a note that it's offline. It's a friendly first Java project for learning how programs talk to the web: you'll use Java's built-in HttpClient, turn JSON into Java objects with Jackson, handle timeouts and errors, save and load a file, and write tests.
- Estimate
- ~8h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Java HttpClient · Jackson · JUnit 5
Project roadmap
- 01
Set up the project
~1hInstall Java 17 or newer and create a Maven (or Gradle) project, adding jackson-databind and JUnit 5. Write a main class that prints Hello, and configure the build so mvn package creates a runnable jar. Done when: java -jar target/quote.jar prints Hello.
- 02
Call the quote API
~1.5hUse java.net.http.HttpClient with a 5-second connect timeout to send a GET request to a free quote API such as https://dummyjson.com/quotes/random, with a 10-second request timeout. Print the status code and the raw response body. Treat any status other than 200 as an error. Done when: running the program prints the JSON returned by the API.
- 03
Turn the JSON into a Java object
~1.5hCreate a Quote record with the fields text and author, and use Jackson's ObjectMapper to read the JSON into it, mapping the API's field names (such as quote) to yours with @JsonProperty, and ignoring fields you don't need. Print the quote in a nice format, wrapping long lines at 70 characters. Done when: the program prints a formatted quote with its author.
- 04
Save and reuse the last quote
~1.5hAfter each successful fetch, save the quote as JSON to a file in the user's home folder (such as ~/.quote-cache.json) with Jackson, along with the time it was saved. When the request fails (no internet, timeout, bad status or invalid JSON), load and print the cached quote with a note like (offline, saved 2 hours ago). If there's no cache either, print a friendly error and exit with code 1. Done when: turning off the internet shows the saved quote.
- 05
Add options
~1hAccept two simple arguments: --offline to always use the cached quote, and --json to print the quote as JSON instead of formatted text. Print a short help message for unknown arguments. Done when: both options work, and an unknown option prints the help.
- 06
Write tests
~1.5hSplit the code into small classes (a QuoteClient, a QuoteCache and a formatter) so they can be tested. Write JUnit tests for parsing a sample JSON string, for the line wrapping, for saving and loading the cache in a temporary folder, and for falling back to the cache when the client throws an error (using a fake client). Done when: mvn test passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack