Refactor: remove HttpExtensions and inline HTTP method mapping

Removed HttpExtensions.cs and its extension methods for RestType-to-HttpMethod conversion. Introduced a private static CreateHttpRequestMessage method in InvokeRecActionViewCommandHandler to handle HTTP method mapping and request creation directly, reducing indirection and simplifying dependencies.
This commit is contained in:
2026-03-02 14:31:38 +01:00
parent ec119a3045
commit 0e7870b556
2 changed files with 21 additions and 32 deletions

View File

@@ -38,9 +38,7 @@ public class InvokeRecActionViewCommandHandler(
$"Id: {action.Id}"
);
using var httpReq = restType
.ToHttpMethod()
.ToHttpRequestMessage(action.EndpointUri);
using var httpReq = CreateHttpRequestMessage(restType, action.EndpointUri);
if (action.Body is not null)
httpReq.Content = new StringContent(action.Body);
@@ -136,4 +134,24 @@ public class InvokeRecActionViewCommandHandler(
return response.IsSuccessStatusCode;
}
private static HttpRequestMessage CreateHttpRequestMessage(RestType restType, string? endpointUri)
{
var method = restType switch
{
RestType.Get => HttpMethod.Get,
RestType.Post => HttpMethod.Post,
RestType.Put => HttpMethod.Put,
RestType.Delete => HttpMethod.Delete,
RestType.Patch => HttpMethod.Patch,
RestType.Head => HttpMethod.Head,
RestType.Options => HttpMethod.Options,
RestType.Trace => HttpMethod.Trace,
RestType.Connect => HttpMethod.Connect,
RestType.None => throw new ArgumentOutOfRangeException(nameof(restType), $"The RestType value '{restType}' is not valid."),
_ => new HttpMethod(restType.ToString().ToUpperInvariant())
};
return new HttpRequestMessage(method, endpointUri);
}
}