By: Daniel Lim-Apo
This project is a simple, straightforward ASP.NET Core Web API application that manages a "To-Do" list. It is built using .NET 10 and demonstrates fundamental concepts of creating RESTful APIs with C# and Entity Framework Core.
The API uses an In-Memory Database, which means that the data is not persisted across application restarts. This makes it an excellent, lightweight example for learning and testing without needing to set up a separate database server.
- RESTful Architecture: Implements standard HTTP methods (GET, POST, PUT, DELETE) for resource management.
- Entity Framework Core: Uses EF Core with an In-Memory provider for data access.
- Minimal Configuration: Easy to run and understand, perfect for beginners learning ASP.NET Core.
- Built-in HTTP Tests: Includes
.httpfiles to easily test endpoints directly from your IDE (like Visual Studio or VS Code).
- .NET 10 SDK or later.
- An IDE such as Visual Studio 2022, Visual Studio Code, or JetBrains Rider.
Ensure you have the project cloned to your local machine.
Navigate to the src directory (where the TodoApi.csproj file is located) and run the following command to restore dependencies and build the project:
cd src
dotnet buildStart the API using the .NET CLI:
dotnet runThe API will start listening for requests. By default, it usually runs on http://localhost:5000 or https://localhost:5001. The exact ports can be found in the console output or the Properties/launchSettings.json file.
The API exposes the following endpoints under the /api/TodoItems route:
| HTTP Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
| GET | /api/TodoItems |
Retrieves a list of all to-do items. | None | 200 OK (Array of items) |
| GET | /api/TodoItems/{id} |
Retrieves a specific to-do item by its ID. | None | 200 OK (Item) or 404 Not Found |
| POST | /api/TodoItems |
Creates a new to-do item. | JSON (Name, IsComplete) | 201 Created (Created item) |
| PUT | /api/TodoItems/{id} |
Updates an existing to-do item. | JSON (Id, Name, IsComplete) | 204 No Content or 400/404 |
| DELETE | /api/TodoItems/{id} |
Deletes a to-do item by its ID. | None | 204 No Content or 404 Not Found |
When creating or updating an item, the JSON payload should look like this:
{
"id": 1,
"name": "Walk the dog",
"isComplete": false
}You can test the API using standard tools like Postman or curl. However, this project also includes .http files inside the src/Manual-Test-Http-Client directory for quick testing directly from your code editor (requires the REST Client extension in VS Code, or built-in support in Visual Studio 2022 17.6+).
- Make sure the API is running (
dotnet run). - Open any of the included HTTP files located in
src/Manual-Test-Http-Client:TodoApi-1-POST.http- Creates an item.TodoApi-2-GET.http- Fetches all items.TodoApi-3-GET-By-Id.http- Fetches a specific item.TodoApi-4-PUT.http- Updates an item.TodoApi-5-DELETE.http- Deletes an item.
- Click the Send Request button that appears above the HTTP request in your editor to execute it and view the response.