Skip to content

Adding an HTTPMethod str enum to http in stdlib #91996

Closed
@cibofo

Description

@cibofo

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

Metadata

Metadata

Assignees

Labels

type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions