Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is System.Net.Http.HttpMethod a class, not an enum?

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?

like image 883
Tomas Aschan Avatar asked Sep 27 '16 06:09

Tomas Aschan


People also ask

What is the use of httpmethod?

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.

What is system net 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.

What is the difference between HTTP methods and HTTP POST?

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.

What is the difference between HTTP HEAD and get methods?

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.


1 Answers

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.

like image 132
sloth Avatar answered Oct 06 '22 19:10

sloth