BookVaultApi is a modern RESTful Web API built with .NET 10. It serves as a backend service for managing a collection of books, allowing clients to perform standard CRUD (Create, Read, Update, Delete) operations.
- Framework: .NET 10.0 Web API
- Data Access: Entity Framework Core (EF Core 10)
- Object Mapping: AutoMapper
- API Documentation: Scalar / OpenAPI
- Language: C#
The project follows a clean, layered architecture to promote maintainability and separation of concerns:
- Controllers: Handle incoming HTTP requests, validate input, and return appropriate HTTP responses.
- Services: Encapsulate business logic. Controllers interact with services (e.g.,
IBookService) rather than directly with the database. - Data Access: Uses EF Core's
DbContext(AppDbContext) to interact with the database. - DTOs (Data Transfer Objects): Separate data shapes for input/output from internal business models, mapped using AutoMapper.
- /Controllers: Contains the API endpoints (e.g.,
BooksController.cs). - /Data: Contains the EF Core
DbContextand database configurations. - /Models: Represents the core domain entities mapping to the database tables.
- /DTOs: Data Transfer Objects used to shape the data sent and received by the API.
- /Services: Contains the business logic and interfaces (e.g.,
BookService.cs). - /Migrations: EF Core database migration files.
- MappingProfile.cs: Configuration for AutoMapper to map between Models and DTOs.
The primary resource is /api/Books.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/Books |
Retrieves a list of all books. |
GET |
/api/Books/{id} |
Retrieves a specific book by its ID. |
POST |
/api/Books |
Creates a new book using CreateBookDto. |
PUT |
/api/Books/{id} |
Updates an existing book using UpdateBookDto. |
DELETE |
/api/Books/{id} |
Deletes a book by its ID. |
- .NET 10 SDK
- An IDE like Visual Studio, Visual Studio Code, or Rider.
- A SQL Server instance (connection string defined in
appsettings.json, though InMemory can be used for testing).
- Clone the repository.
- Navigate to the project directory:
cd BookVaultApi - Update Database Connection (Optional):
Ensure the
DefaultConnectioninappsettings.jsonpoints to your active database, or use the in-memory database configuration if preferred. - Apply Migrations:
dotnet ef database update
- Run the application:
dotnet run
When running in the Development environment, the API documentation is automatically generated and accessible. Simply navigate to the base URL (e.g., https://localhost:xxxx/scalar) to interact with the API using the Scalar interface.