Skip to content

HenriqueBL/todo-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ Todo API

A RESTful API for task management built with Java 17 and Spring Boot 3.2.

Java Spring Boot Maven H2 License


๐Ÿ“Œ About

Todo API is a backend project that implements a full CRUD for task management, following development best practices such as MVC pattern, layered architecture, DTOs, global exception handling, and data validation.

Built as a study project to demonstrate the Spring Boot ecosystem with an in-memory H2 database.


๐Ÿš€ Tech Stack

Technology Version Purpose
Java 17 Main language
Spring Boot 3.2.4 Core framework
Spring Data JPA 3.2.4 Data persistence
Spring Validation 3.2.4 DTO validation
H2 Database Runtime In-memory database
Lombok Latest Boilerplate reduction
JUnit 5 Latest Unit testing
Mockito Latest Dependency mocking

๐Ÿ—๏ธ Architecture

src/main/java/com/example/todoapi/
โ”‚
โ”œโ”€โ”€ controller/          # Presentation layer โ€” handles HTTP requests
โ”œโ”€โ”€ service/             # Business layer โ€” application logic and rules
โ”‚   โ””โ”€โ”€ impl/            # Service implementations
โ”œโ”€โ”€ repository/          # Data layer โ€” database communication
โ”œโ”€โ”€ model/               # JPA entities
โ”œโ”€โ”€ dto/                 # Data transfer objects
โ”‚   โ”œโ”€โ”€ TaskRequestDTO   # Input data
โ”‚   โ””โ”€โ”€ TaskResponseDTO  # Output data
โ””โ”€โ”€ exception/           # Global error handling
    โ”œโ”€โ”€ TaskNotFoundException
    โ”œโ”€โ”€ ErrorResponse
    โ””โ”€โ”€ GlobalExceptionHandler

โš™๏ธ Prerequisites


๐Ÿ”ง Getting Started

1. Clone the repository

git clone https://github.com/henriquebl/todo-api.git
cd todo-api

2. Run with Maven

./mvnw spring-boot:run

3. Or build and run the JAR

./mvnw clean package
java -jar target/todo-api-0.0.1-SNAPSHOT.jar

The application will be available at http://localhost:8080


๐Ÿ“ก Endpoints

Base URL: http://localhost:8080/api/tasks

Method Endpoint Description Status
GET /api/tasks List all tasks 200 OK
GET /api/tasks?completed=true Filter by status 200 OK
GET /api/tasks/{id} Get task by ID 200 OK
POST /api/tasks Create a new task 201 Created
PUT /api/tasks/{id} Update an existing task 200 OK
DELETE /api/tasks/{id} Delete a task 204 No Content

๐Ÿ“‹ Usage Examples

Create a task

POST /api/tasks
Content-Type: application/json

{
  "title": "Study Spring Boot",
  "description": "Finish the To-Do List project",
  "completed": false
}

Response 201 Created:

{
  "id": 1,
  "title": "Study Spring Boot",
  "description": "Finish the To-Do List project",
  "completed": false,
  "createdAt": "2026-03-20T02:30:00",
  "updatedAt": "2026-03-20T02:30:00"
}

List all tasks

GET /api/tasks

Response 200 OK:

[
  {
    "id": 1,
    "title": "Study Spring Boot",
    "description": "Finish the To-Do List project",
    "completed": false,
    "createdAt": "2026-03-20T02:30:00",
    "updatedAt": "2026-03-20T02:30:00"
  }
]

Update a task

PUT /api/tasks/1
Content-Type: application/json

{
  "title": "Study Spring Boot",
  "description": "Finish the To-Do List project",
  "completed": true
}

Delete a task

DELETE /api/tasks/1

Response 204 No Content โ€” no body.


โš ๏ธ Error Handling

Resource not found 404

{
  "status": 404,
  "message": "Task not found with id: 99",
  "timestamp": "2026-03-20T02:30:00"
}

Invalid data 400

{
  "status": 400,
  "message": "Validation error",
  "timestamp": "2026-03-20T02:30:00",
  "errors": [
    "title: Title must be between 3 and 100 characters"
  ]
}

๐Ÿ—„๏ธ Database

This project uses H2 in-memory database โ€” data is lost when the application restarts.

Access the visual console at: http://localhost:8080/h2-console

Field Value
JDBC URL jdbc:h2:mem:tododb
User Name sa
Password (leave blank)

๐Ÿงช Tests

# Run all tests
./mvnw test

# Run with coverage report
./mvnw test jacoco:report

Tests cover the service layer using JUnit 5 and Mockito, validating both success scenarios and exception handling.


๐Ÿ“ Configuration

Located at src/main/resources/application.properties:

server.port=8080
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

๐Ÿ”ฎ Roadmap

  • Authentication with Spring Security + JWT
  • API documentation with Swagger / OpenAPI
  • Migrate to PostgreSQL
  • Pagination and sorting on list endpoints
  • Deploy to Railway or Render

๐Ÿ‘จโ€๐Ÿ’ป Author

Made by Henrique

LinkedIn GitHub


๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages