using System.Text.Json.Serialization; using Carter; using Microsoft.AspNetCore.Http.HttpResults; namespace App.Modules.Health; /// /// Health check response DTO. /// public record HealthResponse( [property: JsonPropertyName("status")] string Status, [property: JsonPropertyName("request_id")] string RequestId); /// /// Hello response DTO. /// public record HelloResponse( [property: JsonPropertyName("message")] string Message, [property: JsonPropertyName("request_id")] string RequestId); /// /// Carter module for health-related endpoints. /// public class HealthModule : ICarterModule { /// /// Adds health and hello endpoints to the application. /// /// The endpoint route builder. public void AddRoutes(IEndpointRouteBuilder app) { app.MapGet("/health", Health); app.MapGet("/hello", Hello); } /// /// Handles GET /health requests. /// /// The HTTP context. /// Health check response with request ID. private static Ok Health(HttpContext context) { var requestId = context.Items["RequestId"]?.ToString() ?? ""; return TypedResults.Ok(new HealthResponse("ok", requestId)); } /// /// Handles GET /hello requests. /// /// The HTTP context. /// Hello response with request ID. private static Ok Hello(HttpContext context) { var requestId = context.Items["RequestId"]?.ToString() ?? ""; return TypedResults.Ok(new HelloResponse("Hello from {{baseName}}!", requestId)); } }