This project demonstrates the use of ASP.NET Core Minimal APIs to build a lightweight and modern web API.
- Minimal API Design: Lightweight and modular API endpoints.
- Exception Handling: Centralized middleware for handling unhandled exceptions.
- Dependency Injection: Services like
BookServiceare injected into endpoints. - Asynchronous Programming: All endpoints and services are fully asynchronous.
- Health Checks: A
/healthendpoint to monitor the application's status.
- .NET 9 SDK: Ensure you have the .NET 9 SDK installed.
git clone https://github.com/cg-hurst/minimal-api-demo.git
cd minimal-api-demodotnet builddotnet runThe application will start on https://localhost:7101.
- GET /v1/books: Retrieve all books.
- GET /v1/books/{id}: Retrieve a book by its ID.
- POST /v1/books: Add a new book.
- PUT /v1/books: Update an existing book.
- DELETE /v1/books/{id}: Delete a book by its ID.
- GET /v1/health: Check the application's health status.
Program.cs: Configures the application, middleware, and services.AddBookApiExtension.cs: Defines theBooksAPI endpoints.AddHealthApiExtension.cs: Defines theHealthAPI endpoint.BookService.cs: Provides in-memory data storage and operations for books.ExceptionHandlerMiddleware.cs: Handles unhandled exceptions globally.
Run Coverage Report
dotnet test --collect:"XPlat Code Coverage"Generate Report
reportgenerator -reports:<path to xml>/coverage.cobertura.xml -targetdir:coverage-report