This is a REST API implementing an online shopping basket system using .NET 8 and C# 12. The focus is on clean architecture, domain-driven design principles, and REST API best practices. The basket and its items are stored in-memory for simplicity.
- Add an item to the basket
- Add multiple items to the basket
- Remove an item from the basket
- Add multiple of the same item to the basket (increases quantity)
- Retrieve the basket
- Clear the basket
- Ensure all items in the basket have the same currency
- Get the total cost of the basket with VAT (20%)
- Get the total cost of the basket without VAT
- Add discounted items (per-item discount)
- Apply discount codes to the basket (excluding already discounted items)
- Apply shipping cost based on country (UK, US, DE, or default cost)
- Request validation using FluentValidation
- Business rules are also validated, for example positive price and quantity greater than or equal to 1.
- Global exception handling middleware
- Returns 400 responses for validation errors
- Integrated request/response logging middleware
- Application level logging for critical operations
- Swagger/OpenAPI with grouped endpoints
- Explicit response types
- There are some unit tests for the Domain and Application layers.
- Restore dependencies:
dotnet restore
- Build the solution
dotnet build
- Run the API:
dotnet run --project src/Basket.Api/ShoppingBasket.Api.csproj
- Open the browser, and navigate to
http://localhost:5132/index.htmlto access the Swagger page. You can find the port in the console:
Now listening on: http://localhost:5132
dotnet test
- Add support to multiple baskets
- Add authentication/authoriaztion
- Replace in-memory repository with a database
- Add persistence with migrations
- Remove hard-coded discount codes and replace them with codes from the database
- Remove the hard-coded list of countries and their shipping costs and replace them with data from the database
- Support multiple currencies with proper conversion rules
- Improve test coverage with integration tests for API layer
- Add metrics/telemetry
- Add API rate limits
- Provide Dockerfile for containerized deployment
- Consider using CQRS