This project demonstrates interaction with a REST API using Java's HttpClient. It consists of three tasks: managing user data, retrieving comments from the last post of a user, and fetching open tasks for a user. The project leverages HttpClient for making API requests and Gson for parsing JSON responses.
This project interacts with the https://jsonplaceholder.typicode.com API and consists of the following tasks:
- User Management: Allows creating, updating, deleting, and retrieving user data.
- Fetching Comments from Last Post: Retrieves all comments from the most recent post of a given user and saves them to a JSON file.
- Fetching Incomplete Tasks: Retrieves all pending tasks for a specified user.
These tasks demonstrate API interactions, JSON processing, and file handling in Java.
- REST API Interaction: Uses
HttpClientto send and receive HTTP requests. - JSON Handling: Parses API responses and constructs JSON data using
Gson. - File Storage: Saves API responses to structured JSON files.
- Asynchronous Requests: Efficiently processes API calls without blocking execution.
- Error Handling: Includes exception handling for failed requests.
- Modular Design: Each task is structured in a separate class for maintainability.
- Clear and Structured Output: Ensures well-formatted responses for easy readability.
- Java
HttpClientfor API communicationGsonfor JSON parsing- File I/O for saving data
- Exception Handling for robust request management
Purpose:
- Perform CRUD operations on user data via API requests.
- Retrieve users by ID and username for targeted queries.
Key Concepts Used:
HttpClientfor sending HTTP requests.Gsonfor parsing JSON responses.- Exception handling for failed API requests.
Purpose:
- Identify and fetch comments from the latest post of a specified user.
- Store comments in a structured JSON file named
user-X-post-Y-comments.json(where X is the user ID and Y is the post ID).
Key Concepts Used:
HttpClientfor API requests.- JSON parsing using
Gson. - File handling for storing data.
Purpose:
- Retrieve all tasks assigned to a user and filter out only the pending ones.
Key Concepts Used:
HttpClientfor fetching task data.- JSON filtering to identify incomplete tasks.
- Console output for displaying results in a structured manner.
This project provides practical experience in working with REST APIs in Java, demonstrating how to fetch, process, and store structured data efficiently.