A minimal API for managing a to-do list, allowing users to perform CRUD operations (Create, Read, Update, Delete) on tasks. The API is secured using JWT Authentication, and CORS is enabled to allow cross-origin requests.
- JWT Authentication for secure access to endpoints.
- CRUD operations for managing tasks.
- CORS support for cross-origin requests.
- Uses MySQL as the database.
| HTTP Method | Route | Description | Auth Required |
|---|---|---|---|
| GET | /tasks |
Retrieve all tasks | ✅ |
| POST | /tasks |
Add a new task | ✅ |
| PUT | /tasks/{id} |
Update an existing task | ✅ |
| DELETE | /tasks/{id} |
Delete a task by ID | ✅ |
- .NET 6.0 SDK or higher
- MySQL database
- Postman or any API testing tool (optional)
-
Clone the Repository:
git clone https://github.com/yourusername/todo-api.git cd todo-api -
Install Dependencies:
dotnet restore
-
Set Up the Database: Update the
appsettings.jsonfile with your MySQL connection string:{ "ConnectionStrings": { "ToDoDB": "server=localhost;database=todo;user=root;password=yourpassword" } } -
Run the Application:
dotnet watch run
The API uses JWT for authentication. Obtain a token by using the /register or /login endpoints.
- Retrieves all tasks from the database.
- Headers:
Authorization: Bearer <your-jwt-token>
- Adds a new task.
- Headers:
Authorization: Bearer <your-jwt-token> - Body (JSON):
{ "name": "Task Name", "isComplete": false }
- Updates an existing task by ID.
- Headers:
Authorization: Bearer <your-jwt-token> - Body (JSON):
{ "name": "Updated Task Name", "isComplete": true }
- Deletes a task by ID.
- Headers:
Authorization: Bearer <your-jwt-token>
CORS is enabled to allow any origin to access the API. This is useful during development when your frontend and backend are hosted on different ports.
This project is licensed under the MIT License.
- This project includes Swagger for API documentation. You can access it at
/swaggeronce the application is running. - For the frontend, refer to ToDo List React Client and update the API URL in
service.js.