You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The same as http.HTTPStatus but for http methods.
It can be helpful when dealing with the need to explicitly write the http method name, for example, when using urllib3.
When writing HTTP related code its common to explicitly write HTTP methods names as magic strings which are prone to mistypes and errors.
For example a simple search in amazon's botocore (HTTP related code, https://github.com/boto/botocore) for the string 'GET' shows 77 references and a search for 'POST' shows 43 references.
Example of code now: client.request('GET', url, headers=headers)
Illustration of the same code with the new feature: client.request(HTTPMethod.GET, url, headers=headers)
Feature or enhancement
Adding an HTTPMethod str enum to http in stdlib
Pitch
The same as http.HTTPStatus but for http methods.
It can be helpful when dealing with the need to explicitly write the http method name, for example, when using urllib3.
When writing HTTP related code its common to explicitly write HTTP methods names as magic strings which are prone to mistypes and errors.
For example a simple search in amazon's botocore (HTTP related code, https://github.com/boto/botocore) for the string 'GET' shows 77 references and a search for 'POST' shows 43 references.
Example of code now:
client.request('GET', url, headers=headers)
Illustration of the same code with the new feature:
client.request(HTTPMethod.GET, url, headers=headers)
Which is much safer and more comfortable.
You can see real examples of this when searching for urllib3 examples https://www.programcreek.com/python/example/72024/urllib3
In reality, in many projects, we just create the HTTPMethod enum ourselves which is just an unnecessary duplication of code.
The implementation should follow the appropriate HTTP RFCs listed below:
https://datatracker.ietf.org/doc/html/rfc7231#section-4
https://datatracker.ietf.org/doc/html/rfc5789#section-2
The text was updated successfully, but these errors were encountered: