BsStoreApp is a comprehensive RESTful Web API built with .NET 6 that demonstrates modern web API development practices. The application serves as a book store management system with full CRUD operations, advanced features like pagination, filtering, caching, versioning, and HATEOAS (Hypermedia as the Engine of Application State) implementation.
The project follows Clean Architecture principles with clear separation of concerns:
├── WebApi/ # Entry point and API configuration
├── Presentation/ # Controllers and API presentation layer
├── Services/ # Business logic and service implementations
├── Repositories/ # Data access layer with Entity Framework
└── Entities/ # Domain models, DTOs, and shared contracts
- Repository Pattern: Abstracts data access logic
- Service Layer Pattern: Encapsulates business logic
- Dependency Injection: Promotes loose coupling and testability
- DTO Pattern: Separates internal models from API contracts
- CQRS-like approach: Separate DTOs for different operations
- 📚 Complete Book Management: Create, Read, Update, Delete operations
- 🔍 Advanced Filtering: Filter books by various criteria
- 📄 Pagination: Efficient data retrieval with metadata
- 🔗 HATEOAS: Hypermedia-driven API responses
- 📝 Partial Updates: JSON Patch support for efficient updates
- 🚀 API Versioning: Multiple API versions support
- 💾 Response Caching: Improved performance with caching strategies
- 📊 Logging: Comprehensive logging with NLog
- 🔒 CORS: Cross-origin resource sharing configuration
- 📋 Data Validation: Robust input validation with action filters
- 🎯 Content Negotiation: Multiple response formats (JSON, XML, CSV)
- 📈 HTTP Cache Headers: Client-side caching optimization
- .NET 6: Latest LTS version of .NET
- ASP.NET Core Web API: RESTful API framework
- Entity Framework Core 7.0.3: Object-relational mapping
- SQL Server LocalDB: Database engine
- AutoMapper 12.0.0: Object-to-object mapping
- NLog 5.1.2: Logging framework
- Microsoft.EntityFrameworkCore: Data access
- Microsoft.AspNetCore.JsonPatch: JSON Patch support
- Microsoft.AspNetCore.Mvc.NewtonsoftJson: JSON serialization
- Microsoft.AspNetCore.Mvc.Versioning: API versioning
- System.Linq.Dynamic.Core: Dynamic LINQ queries
- Marvin.Cache.Headers: HTTP cache headers
-
Clone the repository
git clone https://github.com/yourusername/BsStoreApp.git cd BsStoreApp -
Restore dependencies
dotnet restore
-
Update database connection string (if needed)
Edit
WebApi/appsettings.json:{ "ConnectionStrings": { "sqlConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=bsStoreApp;Integrated Security=true;" } } -
Run database migrations
dotnet ef database update --project WebApi
-
Run the application
dotnet run --project WebApi
-
Access the API
- API Base URL:
https://localhost:7001orhttp://localhost:5001 - Swagger UI:
https://localhost:7001/swagger
- API Base URL:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/books |
Get all books with pagination |
| GET | /api/books/{id} |
Get a specific book |
| POST | /api/books |
Create a new book |
| PUT | /api/books/{id} |
Update a book |
| PATCH | /api/books/{id} |
Partially update a book |
| DELETE | /api/books/{id} |
Delete a book |
| OPTIONS | /api/books |
Get allowed HTTP methods |
| HEAD | /api/books |
Get headers without body |
- Pagination:
pageNumber,pageSize - Filtering:
minPrice,maxPrice,searchTerm - Sorting:
orderBy - Field Selection:
fields
GET /api/books?pageNumber=1&pageSize=10&minPrice=10&maxPrice=100POST /api/books
Content-Type: application/json
{
"title": "Clean Code",
"price": 45.99
}PATCH /api/books/1
Content-Type: application/json-patch+json
[
{
"op": "replace",
"path": "/price",
"value": 39.99
}
]Logging is configured via nlog.config:
- Log files are stored in
./logs/directory - Internal logs are stored in
./internal_logs/ - Configurable log levels and targets
- Response Caching: 5-minute cache profile for GET requests
- HTTP Cache Headers: 80-second max-age with public cache location
- Cache Validation: Configurable revalidation settings
- Allows all origins, methods, and headers
- Exposes
X-Paginationheader for pagination metadata
- Navigate to
https://localhost:7001/swagger - Explore and test all available endpoints
- View request/response schemas
- Import the API collection (if available)
- Set base URL to
https://localhost:7001 - Test various endpoints with different parameters
BsStoreApp/
├── Entities/
│ ├── DTOs/ # Data Transfer Objects
│ ├── Models/ # Domain Models
│ ├── Exceptions/ # Custom Exceptions
│ ├── RequestFeatures/ # Pagination and Filtering
│ └── LinkModels/ # HATEOAS Link Models
├── Repositories/
│ ├── Contracts/ # Repository Interfaces
│ └── EFCore/ # Entity Framework Implementations
├── Services/
│ ├── Contracts/ # Service Interfaces
│ └── *.cs # Service Implementations
├── Presentation/
│ ├── Controllers/ # API Controllers
│ └── ActionFilters/ # Custom Action Filters
└── WebApi/
├── Extensions/ # Service Extensions
├── Utilities/ # Helper Classes
└── Program.cs # Application Entry Point
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Ahmet Coşkun Kızılkaya
- Clean Architecture principles by Robert C. Martin
- RESTful API design best practices
- ASP.NET Core community and documentation
- Entity Framework Core team
⭐ If you found this project helpful, please give it a star!