This is a RESTful API for a movie tracking application, built with Spring Boot. It handles user authentication and provides a foundation for movie-related functionalities.
- User authentication using JWT (JSON Web Tokens).
- Secure cookie-based session management.
- Containerized setup with Docker for easy development and deployment.
Before you begin, ensure you have the following installed on your system:
- Java 17 or later
- Docker
- Docker Compose
Follow these steps to get the application up and running.
git clone https://github.com/panosdim/movies-track-api.git
cd movies-track-apiThe application uses a .env file for configuration. Create a .env file in the root of the project by copying the example file:
cp .env.example .envNow, open the .env file and set the required environment variables:
# PostgreSQL Database settings
DB_USER=your_db_user
DB_PASSWORD=your_strong_db_password
# JWT Settings
# The JWT_SECRET must be a Base64-encoded string.
# You can generate a suitable key using an online tool or the following command:
# openssl rand -base64 32
JWT_SECRET=c29tZXN1cGVyc2VjcmV0and0a2V5dGhhdGlzYXRsZWFzdDI1NmJpdHNsb25n
JWT_EXPIRATION_MS=86400000 # 24 hoursImportant: The
JWT_SECRETmust be a Base64 encoded string that is sufficiently long for the HMAC-SHA algorithm used (e.g., 256, 384, or 512 bits).
The compose.yaml file is configured to build and run the entire application stack, including the PostgreSQL database.
Run the following command to start the services in detached mode:
docker compose up --build -dThe API will be available at http://localhost:8080.
If you prefer to run the application directly using Gradle for development, you can do so after configuring the .env file.
First, ensure your environment variables from .env are loaded. This is crucial for the application to pick up database and JWT settings.
set -o allexport
source .env
set +o allexport
./gradlew bootRunThe application will be available at http://localhost:8080.
Here are the available API endpoints.
Authenticates a user and returns a JWT in an HTTP-only cookie.
Request Body:
{
"email": "user@example.com",
"password": "password123"
}Success Response (200 OK):
- An
HttpOnlycookie namedjwtis set in the response headers. - The response body contains user information:
{ "firstName": "John", "lastName": "Doe" }
Error Response (401 Unauthorized):
- Returned if the email or password is incorrect.
- Spring Boot - The web framework used
- PostgreSQL - Database
- Docker - Containerization
- Gradle - Dependency Management
- jjwt - Java library for JWT