TODO API

A demo Spring Boot REST API for managing TODO items with mock data.

Features

  • REST API for TODO CRUD operations
  • Mock data service (no database required)
  • Comprehensive unit tests
  • Docker support
  • VS Code Dev Container ready

Prerequisites

  • Java 17+
  • Maven 3.6+
  • Docker (optional)

Quick Start

Run Locally

./mvnw spring-boot:run

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

API Documentation

OpenAPI documentation is available at:

  • Swagger UI: http://localhost:8080/swagger-ui/index.html
  • OpenAPI JSON: http://localhost:8080/v3/api-docs

Run Tests

./mvnw test

Build JAR

./mvnw clean package
java -jar target/todo-api-1.0.0.jar

Docker

Build Image

docker build -t todo-api .

Run Container

docker run -p 8080:8080 todo-api

API Endpoints

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

Method Endpoint Description
GET /api/todos Get all todos
GET /api/todos/{id} Get todo by ID
POST /api/todos Create new todo
PUT /api/todos/{id} Update existing todo
DELETE /api/todos/{id} Delete todo

Example Usage

Get All Todos

curl http://localhost:8080/api/todos

Create Todo

curl -X POST http://localhost:8080/api/todos \
  -H "Content-Type: application/json" \
  -d '{"title":"New Task","description":"Task description","completed":false}'

Update Todo

curl -X PUT http://localhost:8080/api/todos/1 \
  -H "Content-Type: application/json" \
  -d '{"title":"Updated Task","description":"Updated description","completed":true}'

Delete Todo

curl -X DELETE http://localhost:8080/api/todos/1

Development

VS Code Dev Container

Open the project in VS Code and select "Reopen in Container" when prompted, or use the Command Palette: Remote-Containers: Reopen in Container

Sample Data

The application starts with 3 sample todos:

  1. "Learn Spring Boot" - not completed
  2. "Build TODO API" - not completed
  3. "Write unit tests" - completed

Project Structure

src/
├── main/java/com/demo/todoapi/
│   ├── TodoApiApplication.java     # Main application class
│   ├── controller/
│   │   └── TodoController.java     # REST controller
│   ├── model/
│   │   └── Todo.java              # Todo model
│   └── service/
│       └── TodoService.java       # Business logic with mock data
└── test/java/com/demo/todoapi/
    ├── controller/
    │   └── TodoControllerTest.java # Controller tests
    └── service/
        └── TodoServiceTest.java    # Service tests