Skip to content

Commit

Permalink
Support patch method (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Sep 1, 2021
1 parent b6078f4 commit aee6f6d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions aio_request/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Method:
POST = "POST"
PUT = "PUT"
DELETE = "DELETE"
PATCH = "PATCH"


class Header:
Expand Down
42 changes: 42 additions & 0 deletions aio_request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ def put(
)


def patch(
url: Union[str, yarl.URL],
body: Optional[bytes] = None,
*,
headers: Optional[Headers] = None,
path_parameters: Optional[PathParameters] = None,
query_parameters: Optional[QueryParameters] = None,
) -> Request:
return build_request(
Method.PATCH,
url,
path_parameters=path_parameters,
query_parameters=query_parameters,
headers=headers,
body=body,
)


def delete(
url: Union[str, yarl.URL],
*,
Expand Down Expand Up @@ -109,6 +127,30 @@ def put_json(
)


def patch_json(
url: Union[str, yarl.URL],
data: Any,
*,
path_parameters: Optional[PathParameters] = None,
query_parameters: Optional[QueryParameters] = None,
headers: Optional[Headers] = None,
encoding: str = "utf-8",
dumps: Callable[[str], Any] = json.dumps,
content_type: str = "application/json",
) -> Request:
return build_json_request(
Method.PATCH,
url,
data,
path_parameters=path_parameters,
query_parameters=query_parameters,
headers=headers,
encoding=encoding,
dumps=dumps,
content_type=content_type,
)


def build_json_request(
method: str,
url: Union[str, yarl.URL],
Expand Down
1 change: 1 addition & 0 deletions aio_request/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def setup_v2(
Method.POST: unsafe_method_strategy,
Method.PUT: unsafe_method_strategy,
Method.DELETE: unsafe_method_strategy,
Method.PATCH: unsafe_method_strategy,
}
)
return DefaultClient(
Expand Down

0 comments on commit aee6f6d

Please sign in to comment.