A RESTful API built with Java and Spring Boot, featuring full CRUD operations and automated unit testing.
- Create a todo item via POST request
- Read all todo items via GET request
- Complete a todo item via PATCH request
- Delete a todo item via DELETE request
- 5 automated unit tests with JUnit 5, all passing
| Technology | Purpose |
|---|---|
| Java 21 | Primary language |
| Spring Boot 3.5 | Application framework |
| Spring Web (MVC) | RESTful API layer |
| Maven | Build tool & dependency management |
| JUnit 5 | Automated unit testing |
| Spring DevTools | Hot reload during development |
- Designed and implemented a layered architecture (Controller → Service → Data)
- Built 4 RESTful endpoints following HTTP method conventions (GET / POST / PATCH / DELETE)
- Applied dependency injection via Spring's IoC container
- Used Java generics and collections (
List<Todo>,ArrayList) - Used lambda expressions for list filtering
- Wrote 5 JUnit unit tests covering normal and edge cases (e.g. deleting a non-existent item)
- Used
@BeforeEachto ensure test isolation - Managed project dependencies with Maven (pom.xml)
| Method | Endpoint | Description |
|---|---|---|
| GET | /todos |
Get all todo items |
| POST | /todos |
Create a new todo item |
| PATCH | /todos/{id}/complete |
Mark a todo as complete |
| DELETE | /todos/{id} |
Delete a todo item |
Prerequisites: Java 21+, Maven
git clone https://github.com/96528025/todo-api.git
cd todo-api
./mvnw spring-boot:runServer runs on http://localhost:8080
./mvnw testExpected output: Tests run: 6, Failures: 0, Errors: 0 — BUILD SUCCESS
# Create a todo
curl -X POST http://localhost:8080/todos -H "Content-Type: text/plain" -d "Buy groceries"
# Get all todos
curl http://localhost:8080/todos
# Mark complete
curl -X PATCH http://localhost:8080/todos/1/complete
# Delete
curl -X DELETE http://localhost:8080/todos/1用 Java 和 Spring Boot 构建的 RESTful API,支持完整的增删改查操作,并包含自动化单元测试。
- 创建待办事项(POST 请求)
- 查询所有待办事项(GET 请求)
- 标记完成某个待办事项(PATCH 请求)
- 删除某个待办事项(DELETE 请求)
- 5 个自动化单元测试,使用 JUnit 5,全部通过
| 技术 | 用途 |
|---|---|
| Java 21 | 主要编程语言 |
| Spring Boot 3.5 | 应用框架 |
| Spring Web (MVC) | RESTful API 层 |
| Maven | 构建工具 & 依赖管理 |
| JUnit 5 | 自动化单元测试 |
| Spring DevTools | 开发时热重载 |
- 设计并实现了分层架构(Controller → Service → 数据层)
- 构建了 4 个 RESTful 接口,遵循 HTTP 方法规范(GET / POST / PATCH / DELETE)
- 通过 Spring IoC 容器实现依赖注入
- 使用了 Java 泛型和集合(
List<Todo>、ArrayList) - 使用 Lambda 表达式进行列表过滤
- 编写了 5 个 JUnit 单元测试,覆盖正常情况和边界情况(如删除不存在的条目)
- 使用
@BeforeEach确保每个测试相互独立 - 通过 Maven(pom.xml) 管理项目依赖
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /todos |
获取所有待办事项 |
| POST | /todos |
创建新的待办事项 |
| PATCH | /todos/{id}/complete |
标记某条待办为完成 |
| DELETE | /todos/{id} |
删除某条待办事项 |
前置要求: Java 21+,Maven
git clone https://github.com/96528025/todo-api.git
cd todo-api
./mvnw spring-boot:run服务器默认运行在 http://localhost:8080
./mvnw test预期输出:Tests run: 6, Failures: 0, Errors: 0 — BUILD SUCCESS
# 创建待办
curl -X POST http://localhost:8080/todos -H "Content-Type: text/plain" -d "买牛奶"
# 查询所有
curl http://localhost:8080/todos
# 标记完成
curl -X PATCH http://localhost:8080/todos/1/complete
# 删除
curl -X DELETE http://localhost:8080/todos/1