HttpStatusCode
is implemented as an enum
, with each possible value assigned to its corresponding HTTP status code (e.g. (int)HttpStatusCode.Ok == 200
).
However, HttpMethod
is implemented as a class
, with static properties to get instances for the various HTTP verbs (HttpMethod.Get
, HttpMethod.Put
etc). What is the rationale behind not implementing HttpMethod
as an enum
?
The most common usage of HttpMethod is to use one of the static properties on this class. However, if an app needs a different value for the HTTP method, the HttpMethod constructor initializes a new instance of the HttpMethod with an HTTP method that the app specifies. Initializes a new instance of the HttpMethod class with a specific HTTP method.
System. Net. Http System. Net. Http A helper class for retrieving and comparing standard HTTP methods and for creating new HTTP methods. The most common usage of HttpMethod is to use one of the static properties on this class.
An HTTP method. Represents an HTTP OPTIONS protocol method. Gets the HTTP PATCH protocol method. Represents an HTTP POST protocol method that is used to post a new entity as an addition to a URI. Represents an HTTP PUT protocol method that is used to replace an entity identified by a URI.
Represents an HTTP HEAD protocol method. The HEAD method is identical to GET except that the server only returns message-headers in the response, without a message-body. An HTTP method. Represents an HTTP OPTIONS protocol method. Gets the HTTP PATCH protocol method.
From the documentation (emphasis mine):
Remarks
The most common usage of HttpMethod is to use one of the static properties on this class. However, if an app needs a different value for the HTTP method, the HttpMethod constructor initializes a new instance of the HttpMethod with an HTTP method that the app specifies.
Which is of course not possible with an enum.
See its constructor and method property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With