This project is a .NET 7 class library and console application that demonstrates integration with the public Reqres API to fetch user information using HttpClient, with support for Clean Architecture, in-memory caching, error handling, retry logic, and the Options pattern.
- 🔌 API Client using
HttpClient
withIHttpClientFactory
- 📦 Strongly typed models (DTOs) with JSON mapping
- 🧱 Clean Architecture structure (Domain, Application, Infrastructure, Presentation)
- ♻️ In-Memory Caching with configurable expiration
- 🔁 Retry logic for transient failures using Polly
- ⚙️ Options Pattern to configure base URL and headers
- 🧪 Unit Tests for services
- 📺 Console App demonstrating usage
/src
│
├── Domain/
├── Application/
├── Infrastructure/
├── Presentation/
└── Tests/
appsettings.json
or options pattern is used to configure:
{
"ReqresApiOptions": {
"BaseUrl": "https://reqres.in/api/",
"ApiKey": "reqres-free-v1",
"CacheDurationInMinutes": 5
}
}
Registered via:
services.Configure<ReqresApiOptions>(configuration.GetSection("ReqresApiOptions"));
services.AddHttpClient<IUserService, ExternalUserService>()
.AddPolicyHandler(...) // Polly retry logic
- Clone the repository
git clone https://github.com/your-username/reqres-api-integration.git
cd reqres-api-integration
- Build the project
dotnet build
- Run the console application
dotnet run --project src/Presentation
Run unit tests from the test project:
dotnet test
var user = await _userService.GetUserByIdAsync(2);
Console.WriteLine($"{user.FirstName} {user.LastName} - {user.Email}");
var allUsers = await _userService.GetAllUsersAsync();
- Clean Architecture: Separation of concerns between layers improves maintainability and testability.
- Polly: To handle transient faults like network issues.
- IMemoryCache: Improves performance by reducing repeated API calls.
- Options Pattern: Allows flexible configuration of API endpoints and settings.
MIT License