Skip to content

iplantemn/imdb-movies-api

Repository files navigation

imdb-movies-api

Movies API for the IMDB SmartThings project.

Movies 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 Repository with simple annotations. This REST API supports sorting & pagination out of the box.

Build

Movies 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.

Deployments

Warning: The first deployment of the application will be slower than the subsequent deployments, because the application will seed the database.

Prerequisites

Before you can deploy the application:

  1. the executable .jar must be generated by running the build Gradle task
  2. the database must be deployed to Docker

Database

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:

  1. Ensure that Docker is running on your system
  2. From the root of the imdb-movies-api project, run the following command:
docker-compose up movies-db --build

Local API deployment

Once 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/movies-<version>-.jar

Docker API deployment

Once you have executed the Gradle build task, you can deploy the Spring Boot application as such:

docker-compose up movies-api --build # if the database is already deployed

Usage

The application is accessible at the following base URLs:

Environment Base URL
Local http:https://localhost:8080
Docker http:https://localhost:5012

API Docs

Postman

For easy interaction with the API, you can import the Postman collection in ./postman.

HATEOAS

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:https://localhost:8080/api/v1/movies # Local
curl -X GET http:https://localhost:5012/api/v1/movies # Docker

Spring Boot Actuator

You can also use the Spring Boot Actuator mappings endpoint to get a list of endpoints:

curl -X GET 'http:https://localhost:8080/actuator/mappings' # Local
curl -X GET 'http:https://localhost:5012/actuator/mappings' # Docker