An open API service indexing awesome lists of open source software.

https://github.com/samef/asp.net-core-todo-api

To-do API project
https://github.com/samef/asp.net-core-todo-api

aspnet-core-webapi csharp dependency-injection entity-framework-core rest-api

Last synced: about 1 month ago
JSON representation

To-do API project

Awesome Lists containing this project

README

        

This project is a demonstration of a back-end API for a simple to-do application, built using ASP.NET Core Web API. It showcases foundational concepts in CRUD operation handling, defensive coding practices, and database management with Entity Framework Core. By structuring the solution across three distinct projects—Todo.API, Todo.Logic, and Todo.Entity—the project ensures a clean separation of concerns, making it easy to extend, maintain, and understand.

The Todo.API project hosts all the API endpoints, designed to follow RESTful principles, with each endpoint mapped to perform CRUD operations on to-do items. Acting as the primary interface with the client, Todo.API manages HTTP routing, captures and logs exceptions, and sends appropriate HTTP status codes in responses. This project configures dependency injection for key services, like TodoItemService and TodoItemRepository, and controls interactions between the client and the core business logic layer. It functions strictly as a middle layer, delegating any heavy lifting to the Todo.Logic project.

The Todo.Logic project is the core of the application’s functionality and acts as the service layer where all business logic is processed. This layer ensures that the rules of the application are enforced, data is validated, and requests and responses are transformed as needed. Acting as the mediator between the API and data access layers, Todo.Logic defines services like TodoItemService to perform complex operations, retrieve data, and validate input. Defensive coding practices are implemented here, ensuring parameters are checked, data is transformed consistently, and potential errors are minimized before requests reach the data layer. The Todo.Logic project maintains control over how data is handled, guaranteeing that the API layer only needs to handle requests and responses, while Todo.Logic applies the necessary transformations and validations.

The Todo.Entity project is dedicated to data access and is solely responsible for the application’s interactions with the database. This project uses Entity Framework Core to set up database mappings, ensuring that entities like TodoItem are properly structured and aligned with the database schema. Todo.Entity is designed to function as a straightforward bridge to the database, providing CRUD operations via repository classes like TodoItemRepository without embedding any business logic. By using the repository pattern, it abstracts the complexities of database management, making data access more modular and testable.

To set up the project, first, configure the connection string in appsettings.json under ConnectionStrings:DefaultConnection. Dependency injection is set up in Program.cs, where TodoItemService, TodoItemRepository, and AppDbContext are registered. You can then use the Entity Framework Core CLI or the Package Manager Console to apply migrations for initial database setup. Testing is straightforward using tools like Postman, where sample JSON payloads for requests (such as TodoItemCreateRequest) can be provided for quick endpoint verification.