Skip to content

Lil-Code30/taskmanager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‹ Task Manager REST API

A modern RESTful Task Management API built with Spring Boot, Spring Data JPA, Hibernate, and an H2 In-Memory Database.

This project demonstrates enterprise Java backend development concepts including:

  • REST API Design
  • CRUD Operations
  • DTO Pattern
  • Validation
  • Repository Pattern
  • Service Layer Architecture
  • Pagination
  • Sorting
  • Searching
  • Filtering
  • Custom JPQL Queries
  • Exception Handling
  • ResponseEntity
  • Spring Boot Best Practices

πŸ“‘ Table of Contents

  • Features
  • Tech Stack
  • Project Structure
  • Architecture
  • Database
  • Running the Project
  • H2 Database Console
  • API Documentation
  • Request & Response Examples
  • Pagination
  • Sorting
  • Searching
  • Validation
  • HTTP Status Codes
  • Testing Endpoints
  • Future Improvements
  • Author

✨ Features

  • Create Tasks
  • Update Tasks
  • Delete Tasks
  • Get Task By ID
  • Get All Tasks
  • Pagination
  • Sorting
  • Search by Title
  • Filter by Completion Status
  • Search using Multiple Filters
  • DTO Mapping
  • Bean Validation
  • H2 In-Memory Database
  • Spring Data JPA
  • Custom JPQL Queries

πŸ›  Tech Stack

Technology Version
Java 21+
Spring Boot 3.x
Spring Web βœ“
Spring Data JPA βœ“
Hibernate βœ“
H2 Database βœ“
Maven βœ“
Lombok βœ“
Jakarta Validation βœ“

πŸ“ Project Structure

src
β”‚
β”œβ”€β”€ controller
β”‚      TaskController.java
β”‚
β”œβ”€β”€ service
β”‚      TaskService.java
β”‚      TaskServiceImpl.java
β”‚
β”œβ”€β”€ repository
β”‚      TaskRepository.java
β”‚
β”œβ”€β”€ entity
β”‚      Task.java
β”‚
β”œβ”€β”€ dto
β”‚      TaskRequest.java
β”‚      TaskResponse.java
β”‚
β”œβ”€β”€ exception
β”‚
└── TaskManagerApplication.java

πŸ› Architecture

Client
   β”‚
HTTP Request
   β”‚
TaskController
   β”‚
TaskService
   β”‚
TaskRepository
   β”‚
Hibernate
   β”‚
H2 Database

πŸ—„ Database Configuration

The application uses an H2 In-Memory Database.

spring.datasource.url=jdbc:h2:mem:taskdb
spring.datasource.username=sa
spring.datasource.password=password

Because it is an in-memory database, all data is deleted when the application stops.


β–Ά Running the Project

Clone

git clone https://github.com/yourusername/task-manager.git
cd task-manager

Build

mvn clean install

Run

mvn spring-boot:run

Application starts on:

http://localhost:8080

πŸ—„ H2 Console

Enable:

http://localhost:8080/h2-console

Credentials

Field Value
JDBC URL jdbc:h2:mem:taskdb
Username sa
Password password

πŸ“š API Documentation

Base URL

http://localhost:8080/api/v1/tasks

1. Create Task

POST

POST /api/v1/tasks

Request Body

{
  "title": "Learn Spring Boot",
  "description": "Finish REST API section",
  "completed": false
}

Success Response

201 Created

{
  "id": 1,
  "title": "Learn Spring Boot",
  "description": "Finish REST API section",
  "completed": false,
  "createdAt": "2026-07-12T11:20:35"
}

2. Get All Tasks

GET

GET /api/v1/tasks

Supports

  • Pagination
  • Sorting

Example

GET /api/v1/tasks?page=0&size=5

Example

GET /api/v1/tasks?page=0&size=10&sortBy=createdAt&sortDir=DESC

Response

{
  "tasks": [],
  "currentPage": 0,
  "totalItems": 15,
  "totalPages": 2,
  "hasNext": true,
  "hasPrevious": false
}

3. Get Task By ID

GET

GET /api/v1/tasks/{id}

Example

GET /api/v1/tasks/1

Response

{
  "id": 1,
  "title": "Learn Spring Boot",
  "description": "Finish REST API",
  "completed": false,
  "createdAt": "2026-07-12T10:00:00"
}

4. Update Task

POST

POST /api/v1/tasks/{id}

Example

POST /api/v1/tasks/1

Request

{
  "title": "Spring Boot Masterclass",
  "description": "Updated Description",
  "completed": true
}

Response

{
  "id": 1,
  "title": "Spring Boot Masterclass",
  "description": "Updated Description",
  "completed": true,
  "createdAt": "2026-07-12T10:00:00"
}

5. Delete Task

DELETE

DELETE /api/v1/tasks/{id}

Example

DELETE /api/v1/tasks/1

Response

200 OK

6. Get Tasks By Completion Status

GET

GET /api/v1/tasks/completed/{status}

Example

GET /api/v1/tasks/completed/true

or

GET /api/v1/tasks/completed/false

Response

[
  {
    "id": 3,
    "title": "Deploy Project",
    "completed": true
  }
]

7. Search By Title

GET

GET /api/v1/tasks/search-by-title

Example

GET /api/v1/tasks/search-by-title?title=spring

Response

[
  {
    "id": 2,
    "title": "Learn Spring Boot"
  }
]

8. Advanced Search

GET

GET /api/v1/tasks/search

Supports

  • Title
  • Completed
  • Pagination
  • Sorting

Search by Title

GET /api/v1/tasks/search?title=spring

Search by Status

GET /api/v1/tasks/search?completed=true

Search by Title and Status

GET /api/v1/tasks/search?title=spring&completed=false

Search with Pagination

GET /api/v1/tasks/search?page=1&size=5

Search with Sorting

GET /api/v1/tasks/search?sortBy=title&sortDir=ASC

Full Example

GET /api/v1/tasks/search?title=spring&completed=false&page=0&size=5&sortBy=createdAt&sortDir=DESC

Response

{
  "tasks": [],
  "currentPage": 0,
  "totalItems": 7,
  "totalPages": 2,
  "hasNext": true,
  "hasPrevious": false
}

πŸ“– Query Parameters

Parameter Description Default
page Current page 0
size Page size 10
sortBy Field used for sorting createdAt
sortDir ASC or DESC DESC
title Search title Optional
completed Filter completed tasks Optional

βœ… Validation

Current validation uses Jakarta Validation.

Example

@NotBlank
private String title;

@Size(max = 500)
private String description;

Invalid requests return

400 Bad Request

🌐 HTTP Status Codes

Code Meaning
200 OK
201 Created
400 Bad Request
404 Not Found
500 Internal Server Error

πŸ§ͺ Testing the API

Using Postman

Import the endpoints below.

Create

POST http://localhost:8080/api/v1/tasks

Get All

GET http://localhost:8080/api/v1/tasks

Get By ID

GET http://localhost:8080/api/v1/tasks/1

Update

POST http://localhost:8080/api/v1/tasks/1

Delete

DELETE http://localhost:8080/api/v1/tasks/1

Search

GET http://localhost:8080/api/v1/tasks/search?title=spring

Search by Status

GET http://localhost:8080/api/v1/tasks/search?completed=true

Search by Title + Status

GET http://localhost:8080/api/v1/tasks/search?title=spring&completed=false

Search by Title Endpoint

GET http://localhost:8080/api/v1/tasks/search-by-title?title=java

Completion Endpoint

GET http://localhost:8080/api/v1/tasks/completed/true

πŸ“Œ Example SQL

SELECT * FROM TASKS;

SELECT * FROM TASKS
WHERE COMPLETED = TRUE;

SELECT * FROM TASKS
ORDER BY CREATED_AT DESC;

πŸš€ Future Improvements

  • Swagger / OpenAPI Documentation
  • Global Exception Handler
  • JWT Authentication
  • Spring Security
  • PostgreSQL Support
  • Docker
  • Unit Tests
  • Integration Tests
  • Flyway Database Migration
  • MapStruct
  • Logging
  • API Versioning
  • Role-Based Authorization

Tech Stack

  • Java
  • Spring Boot
  • Spring Data JPA
  • Hibernate
  • SQL
  • PostgreSQL
  • REST APIs

About

Spring Boot - Task Manager REST API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors