Skip to content

ManojkumarsharmaIT/UserManagementApp.Api

Repository files navigation

Reqres API Integration (.NET 7 - Clean Architecture)

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.


🚀 Features

  • 🔌 API Client using HttpClient with IHttpClientFactory
  • 📦 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

📂 Project Structure

/src
│
├── Domain/                  
├── Application/             
├── Infrastructure/         
├── Presentation/            
└── Tests/                   

⚙️ Configuration

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

💠 How to Run

  1. Clone the repository
git clone https://github.com/your-username/reqres-api-integration.git
cd reqres-api-integration
  1. Build the project
dotnet build
  1. Run the console application
dotnet run --project src/Presentation

🧪 How to Test

Run unit tests from the test project:

dotnet test

💡 Example Usage

var user = await _userService.GetUserByIdAsync(2);
Console.WriteLine($"{user.FirstName} {user.LastName} - {user.Email}");

var allUsers = await _userService.GetAllUsersAsync();

🧠 Design Decisions

  • 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.

📸 Screenshots

image image image image


📄 License

MIT License

About

User Data Management Using Clean Architecture

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages