using System.Net.Http.Headers; using System.Net.Http.Json; var builder = WebApplication.CreateBuilder(args); builder.Services.AddHttpClient("AffiliateApi", client => { client.BaseAddress = new Uri("YOUR_API_BASE_URL/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("X-Api-Key", "YOUR_API_KEY"); }); var app = builder.Build(); // Minimal API example. The same forwarding pattern can live in: // - an MVC controller action // - a Razor Pages PageModel handler // - a Blazor server-side service // - a background job or integration service app.MapPost("/lead", async (LeadInput input, IHttpClientFactory httpClientFactory) => { var client = httpClientFactory.CreateClient("AffiliateApi"); var response = await client.PostAsJsonAsync("api/leads", new { name = input.Name, email = input.Email, phone = input.Phone, caseTypeId = input.CaseTypeId, message = input.Message, sourceUrl = input.SourceUrl ?? "https://your-site.example/contact" }); var body = await response.Content.ReadAsStringAsync(); return Results.Content(body, "application/json", statusCode: (int)response.StatusCode); }); app.Run(); public sealed class LeadInput { public string Name { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty; public int CaseTypeId { get; set; } public string Message { get; set; } = string.Empty; public string? SourceUrl { get; set; } }