This Spring Boot application is designed to accept requests with text parameters and return relevant books and musics based on the input term. It utilizes the iTunes API for musics and the Google Books API for books, providing a simple and efficient way to search for media related to specific terms.
- Java 17 or newer
- Maven (if not using the Maven Wrapper included)
- Docker (optional, for containerization)
- Internet access for API calls
-
Clone the repository or extract the provided ZIP file to your local machine.
-
Navigate to the application directory where the
pom.xml
file is located. -
Build the application using the Maven Wrapper included in the project. Open a terminal or command prompt in the project directory and run:
./mvnw clean install
If you are on Windows, use:
mvnw.cmd clean install
-
Run the application with:
./mvnw spring-boot:run
On Windows:
mvnw.cmd spring-boot:run
The application will start, and you can access it typically via http://localhost:8080
on your web browser or API testing tool like Postman. Use the appropriate endpoints to send requests with text parameters.
If you prefer to containerize the application using Docker, follow these steps:
-
Build the Docker image. Make sure you are in the project root directory and run:
docker build -t api-challenge .
-
Run the container. After the image is built, start a container with:
docker run -p 8080:8080 api-challenge
This will run the application inside a Docker container, accessible in the same way as the local setup.
To use the application, send a request to http://localhost:8080/search?input=your_search_input
, replacing your_search_input
with the text you're interested in. The application will return a JSON response with up to 5 books and 5 musics related to the search term, including titles and authors/artists.
Before running the application, you must configure the limits for the downstream API calls in the application.properties
file. These settings control the maximum number of books and albums returned by the application:
# Set the maximum number of books to return from the Google Books API
google.books.api.limit=5
# Set the maximum number of albums to return from the iTunes API
apple.musics.api.limit=5
To access the Swagger UI for API documentation and testing, navigate to http://localhost:8080/swagger-ui.html
in your web browser.
The application's health check is available at http://localhost:8080/actuator/health
. This endpoint provides basic application health information.
To access various metrics about the application, visit http://localhost:8080/actuator/metrics
. Specific metrics can be accessed by appending the metric name to the URL, for example to see upstream response time metric call, http://localhost:8080/actuator/metrics/services.upstream.response.time
.