A Spring Boot 3.4.2 RESTful service for managing recipes, featuring JWT‑based authentication, MySQL persistence, and OpenAPI documentation.
- Features
- Tech Stack
- Prerequisites
- Getting Started
- Configuration
- Running the Application
- API Endpoints
- API Documentation
- Data Initialization
- Contributing
- License
- User registration & login with JWT tokens for stateless authentication.
- CRUD‑style read operations on recipes, including pagination and flexible filtering by cuisine, title, ingredients, and cooking time.
- Role‑based security:
/api/auth/**and Swagger UI are publicly accessible; all other endpoints require a valid Bearer token. - CORS support to allow requests from a configured frontend origin.
- OpenAPI/Swagger UI for interactive API exploration.
- Java 17
- Spring Boot 3.4.2
- Spring Data JPA for ORM with Hibernate
- Spring Security + JWT for authentication and authorization
- MySQL as the relational database (via
mysql-connector-j) - Lombok to reduce boilerplate code
- Springdoc OpenAPI (
springdoc-openapi-starter-webmvc-ui) for API docs
- Java 17 or higher
- Maven 3.8+
- MySQL 5.7+ (or compatible)
- Optional: SSL keystore if you plan to run on HTTPS (default port 8443)
-
Clone the repository
git clone https://github.com/codingwitharmand/recipe-api.git cd recipe-api -
Configure MySQL database
- Create a database named
recipe-demo(or change in config) - Update credentials in
src/main/resources/application.yml:spring: datasource: url: jdbc:mysql://localhost:3306/recipe-demo username: your_db_user password: your_db_pass
- Create a database named
-
Set application properties
- In
application.yml, adjust:app: frontend-url: http://localhost:5173 secret-key: your_secret_key expiration-time: 86400000 # in milliseconds server: port: 8443 ssl: key-store: classpath:keystore.p12 key-store-password: password key-store-type: PKCS12 key-alias: your_alias
- In
| Property | Description |
|---|---|
spring.datasource.* |
MySQL connection details |
app.frontend-url |
Allowed CORS origin |
app.secret-key |
Secret for signing JWTs |
app.expiration-time |
JWT expiration in milliseconds |
server.ssl.* |
SSL (HTTPS) configuration |
# Build and run with Maven (uses embedded Maven wrapper)
./mvnw spring-boot:runThe application will start on https://localhost:8443 by default.
| Method | Endpoint | Description | Body |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user | { "username": "...", "password": "..." } |
| POST | /api/auth/login |
Authenticate and get a JWT | { "username": "...", "password": "..." } |
All recipe endpoints require
Authorization: Bearer <token>header.
| Method | Endpoint | Description | Query Params |
|---|---|---|---|
| GET | /api/recipes |
Get paginated list of all recipes | pageNumber (default 0), pageSize (default 10) |
| GET | /api/recipes/filter |
Filter recipes by various fields | cuisine, title, ingredients, maxCookingTime |
Once running, access the interactive Swagger UI at:
https://localhost:8443/swagger-ui.html
The application will run any SQL scripts located in classpath:db/data.sql on startup to seed initial data.
- Fork the repo
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
This project is not released under License.