How shelman2/minimal_api works
Project type and purpose
• This is a backend HTTP API built with .NET 8 using the Minimal API pattern.
• Its sole purpose is to expose a “/weather” endpoint that, given a city name, returns current weather data by calling the external OpenWeatherMap service.
• It’s structured for maintainability: dependency injection, route grouping, separation of concerns, and has unit tests (xUnit/Moq/FluentAssertions).
File structure
• Top-level:
• Api/ ← the web application
• Tests/ ← unit tests for business logic
• WeatherApiSolution.sln
• Api/ contains:
• Program.cs ← entry point, builds the WebApplication
• Extensions/ ← IServiceCollection and IEndpointRouteBuilder extensions for DI and route registration
• Managers/ ← WeatherManager.cs (business logic abstraction)
• Services/ ← OpenWeatherService.cs (HTTP client wrapper for external API)
• Models/ ← WeatherResponse.cs (DTO for API output)
• appsettings*.json← configuration (API key, swagger settings)
• Tests/ contains:
• WeatherManagerTests.cs ← unit tests against WeatherManager (mocking OpenWeatherService)
Pulling insights from README
• Uses Minimal API (no Controllers)
• Employs DI to inject IWeatherManager and IOpenWeatherService
• Registers routes via extension methods
• Swagger UI enabled under Development
• Tests with xUnit, Moq, FluentAssertions
• Configuration-driven (appsettings.json) for OpenWeatherMap API key
Main components
a. Client (HTTP consumer, e.g. browser or Postman)
b. ASP.NET Core Minimal API
• Program.cs
• Route registration (RouteBuilderExtension)
• DependencyInjection setup
• Swagger UI
c. WeatherManager (business logic layer)
d. OpenWeatherService (external API adapter)
e. External OpenWeatherMap API
f. Configuration store (appsettings.json)
g. Unit test project (Tests) – optional to include
Relationships & data flow
1. Client → HTTP GET /weather?city={name}
2. Minimal API Endpoint → routed via RouteBuilderExtension
3. Endpoint handler resolves IWeatherManager from DI container
4. WeatherManager calls IOpenWeatherService.GetCurrentWeatherAsync(city)
5. OpenWeatherService uses HTTPClient to call OpenWeatherMap REST API
6. OpenWeatherMap responds with JSON → deserialized into internal model
7. WeatherManager maps service DTO to WeatherResponse
8. Minimal API returns WeatherResponse JSON to Client
9. Configuration (OpenWeatherApiKey) is read at startup by DI setup
Architectural patterns & principles
• Minimal API (no MVC controllers)
• Dependency Injection (IServiceCollection extensions)
• Separation of Concerns (API layer / Manager layer / Service layer / Model layer)
• Testability (WeatherManager unit tests with Moq)
• Configuration-driven (appsettings.json for secrets)
• Extension methods for clear route and service registration
Technologies & frameworks
• .NET 8, C#, ASP.NET Core Minimal API
• Swagger / Swashbuckle (dev-time API documentation)
• xUnit, Moq, FluentAssertions for unit testing
• HttpClient for external REST calls
• JSON serialization (System.Text.Json)