Build Restful CRUD API for a todo list using Spring Boot.
1. Docker. First, you need to install docker
- Download Docker Here. Hint: Enable Hyper-V feature on Windows and restart.
- Then open powershell and check:
docker version
docker -v
or docker compose version
docker-compose -v
2. Create PostgreSQL database
create database todo_db
3. Change postgreSQL username and password as per your installation
- open
src/main/resources/application.properties
- change
spring.datasource.username
andspring.datasource.password
as per your postgreSQL installation
4. Spring Boot app
- Clone the repository
git clone https://github.com/Erenalp06/todo-list-api.git
- Build the maven project:
mvn clean install
- Running the containers:
This command will build the docker containers and start them.
docker-compose up
The app will start running at http:localhost:9643
Appendix A.
All commands should be run from project root (where docker-compose.yml locates)
- If you have to want to see running containers. Checklist docker containers
docker container list -a
or
docker-compose ps
Screenshot with runnings containers
The app defines following CRUP APIs.
Method | Url | Description | Sample Valid Request Body |
---|---|---|---|
GET | /v1/users/{userId} | Get user by userId with task list | |
POST | /v1/users | Create new user | JSON |
PUT | /v1/users/{userId} | Update user | |
DELETE | /v1/users/{userId} | Delete user by userId |
Method | Url | Description | Sample Valid Request Body |
---|---|---|---|
GET | /v1/tasks/{userId} | Get tasks by userId | |
POST | /v1/tasks/{userId} | Create new task by userId | JSON |
PUT | /v1/tasks/{taskId} | Update task | |
DELETE | /v1/tasks/{taskId} | Delete user by taskId |
Test them using postman or any other rest client.
{
"name": "John Doe",
"email": "johndoe@example.com"
}
{
"title": "Task 3",
"description": "Task 3 description",
"completed": false,
"userId": 1
}