Refactored HTTP method handling by introducing a `ToHttpMethod` extension method in `HttpExtensions.cs` to convert string representations of HTTP methods to `HttpMethod` objects. Replaced manual `HttpMethod` instantiation with the new extension method in `InvokeRecActionCommandHandler` for improved readability and reusability. Removed unused `using` directives from `HttpExtensions.cs` and cleaned up the `namespace` declaration. Added a `using` directive for `ReC.Application.Common` in `InvokeRecActionCommand.cs` to support the new extension method.
18 lines
561 B
C#
18 lines
561 B
C#
namespace ReC.Application.Common;
|
|
|
|
public static class HttpExtensions
|
|
{
|
|
public static HttpMethod ToHttpMethod(this string method) => method.ToUpper() switch
|
|
{
|
|
"GET" => HttpMethod.Get,
|
|
"POST" => HttpMethod.Post,
|
|
"PUT" => HttpMethod.Put,
|
|
"DELETE" => HttpMethod.Delete,
|
|
"PATCH" => HttpMethod.Patch,
|
|
"HEAD" => HttpMethod.Head,
|
|
"OPTIONS" => HttpMethod.Options,
|
|
"TRACE" => HttpMethod.Trace,
|
|
_ => throw new ArgumentException($"Invalid HTTP method: {method}", nameof(method)),
|
|
};
|
|
}
|