Cast API for the IMDB SmartThings project.
Cast API is a Spring Boot application backed by a MySQL database.
This API leverages a few packages on top of Spring Boot for ease of development:
- Project Lombok: provides annotations to replace boilerplate code in POJOs, such as constructors, getters & setters, etc.
- Spring Data REST: automagically implements a fully-fledged RESTful API based on a data
Repositorywith simple annotations. This REST API supports sorting & pagination out of the box.
Cast API uses the Gradle build tool. It is recommended to use the Gradle Wrapper to ensure cross-platform compatibility and enforce a validated version.
- For macOS:
./gradlew <task> - For Windows:
gradlew <task>
Here are the various tasks and how to use them:
| Gradle task | Description |
|---|---|
build |
Complete build task - compiles main and test, runs the test suite and validate coverage, analyzes code with PMD, and builds the .jar |
test |
Compiles the test code, and runs the test suite, validates coverage, and performs PMD analysis. |
pmdMain |
Analyzes main code with PMD. |
pmdTest |
Analyzes test code with PMD. |
You can additionally exclude some parts of a task with the -x flag. For example, gradlew build -x test will exclude all parts of the test task.
Warning: The first deployment of the application will be slower than the subsequent deployments, because the application will seed the database.
Before you can deploy the application:
- the executable
.jarmust be generated by running thebuildGradle task - the database must be deployed to Docker
The database is only meant to be deployed to Docker. The Dockerfile and a SQL script to generate the schema are located in .docker/.
To deploy the MySQL database to Docker:
- Ensure that Docker is running on your system
- From the root of the imdb-cast-api project, run the following command:
docker-compose up cast-db --buildOnce you have executed the Gradle build task and deployed the MySQL database to Docker, you can deploy the Spring Boot application as such:
java -Dspring.profiles.active=local -jar ./build/libs/cast-<version>-.jarOnce you have executed the Gradle build task, you can deploy the Spring Boot application as such:
docker-compose up cast-api --build # if the database is already deployedThe application is accessible at the following base URLs:
| Environment | Base URL |
|---|---|
| Local | http://localhost:8080 |
| Docker | http://localhost:5013 |
For easy interaction with the API, you can import the Postman collection in ./postman.
Spring Data REST publishes its data using HATEOAS, which uses the API responses and hypermedia to deliver a self- documenting API. You can start with:
curl -X GET http://localhost:8080/api/v1/cast # Local
curl -X GET http://localhost:5013/api/v1/cast # DockerYou can also use the Spring Boot Actuator mappings endpoint to get a list of endpoints:
curl -X GET 'http://localhost:8080/actuator/mappings' # Local
curl -X GET 'http://localhost:5013/actuator/mappings' # Docker