Expense Tracker API project from https://roadmap.sh/projects/expense-tracker-api
This is a RESTful API for an expense tracker application. It allows users to manage their expenses by providing endpoints for creating, retrieving, updating, and deleting expenses. The API is built using Spring Boot and uses JWT for authentication.
- Java 17
- Spring Boot 3.3.3
- Spring Security 3.3.3
- Spring Data JPA 3.3.3
- MySQL 9.0.0
- JWT 0.11.5
- Lombok 1.18.34
- Create a MySQL database named
expense_tracker. - Update the database connection details in the
application.propertiesfile.
- Build the application using Maven:
mvn clean install - Run the application:
mvn spring-boot:run
Authentication
- POST /api/auth/register: Register a new user.
- POST /api/auth/login: Login an existing user.
Expenses
- POST /expenses: Create a new expense.
- GET /expenses: Get all expenses for the authenticated user.
- GET /expenses/{id}: Get an expense by ID.
- PUT /expenses/{id}: Update an expense by ID.
- DELETE /expenses/{id}: Delete an expense by ID.
The API uses JWT for authentication. After a successful login, a JWT token is returned in the response header. This token should be included in the Authorization header for all subsequent requests to protected endpoints.
Creating an Expense
POST /expenses Authorization: Bearer <JWT_TOKEN>
{ "amount": 100.00, "description": "Grocery shopping", "category": "Food" }Getting All Expenses
GET /expenses Authorization: Bearer <JWT_TOKEN>