ToDo API This is a simple ToDo API built with Go, using Chi router and JWT for authentication. The API supports creating, updating, and deleting todo items for users. An admin user can manage all todos.
Getting Started
Prerequisites
- Go 1.16 or higher
Running the Project
- Clone the repository: git clone
- Navigate to the project directory: cd
- Install dependencies: go mod download
- Run the server: go run main.go
*Users:
User 1 (admin):
- Username: admin
- Password: adminpw11
user 2:
- Username:user
- Password:userpw22
Endpoints
-
Login:
- POST /login
- Request Body (x-www.form-urlencoded): { "username": "", "password": "" }
- Response:
- 200: "Login successful. Token: "
- 401: "Login failed."
-
User Endpoints:
- List ToDos:
- GET /{username}/todos
- Create ToDo:
- POST /{username}/todos
- Request Body: { "description": "", "percentComplete": }
- Update ToDo:
- PUT /{username}/todos/{id}
- Request Body: { "description": "", "percentComplete": }
- Delete ToDo:
- DELETE /{username}/todos/{id}
- List ToDos:
-
Admin Endpoints:
- List All ToDos:
- GET /admin/todos
- Create Admin ToDo:
- POST /admin/todos
- Request Body: { "description": "", "percentComplete": }
- Update Any User's ToDo:
- PUT /admin/users/{username}/todos/{id}
- Request Body: { "description": "", "percentComplete": }
- Delete Any User's ToDo:
- DELETE /admin/users/{username}/todos/{id}
- List All ToDos:
Note: Regular users can only manage their own ToDos. Admin can manage all users' ToDos.