Skip to content

Commit

Permalink
Expose methods to build requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Jan 9, 2025
1 parent 5391672 commit 33d7b81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions aio_request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
post_json,
put,
put_json,
request,
request_json,
)
from .request_strategy import (
MethodBasedStrategy,
Expand Down Expand Up @@ -111,6 +113,8 @@
"post_json",
"put",
"put_json",
"request",
"request_json",
"RequestEnricher",
"AsyncRequestEnricher",
"DeprecatedAsyncRequestEnricher",
Expand Down
28 changes: 17 additions & 11 deletions aio_request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_request(
return request(
Method.GET,
url,
path_parameters=path_parameters,
Expand All @@ -42,7 +42,7 @@ def post(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_request(
return request(
Method.POST,
url,
path_parameters=path_parameters,
Expand All @@ -64,7 +64,7 @@ def put(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_request(
return request(
Method.PUT,
url,
path_parameters=path_parameters,
Expand All @@ -86,7 +86,7 @@ def patch(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_request(
return request(
Method.PATCH,
url,
path_parameters=path_parameters,
Expand All @@ -107,7 +107,7 @@ def delete(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_request(
return request(
Method.DELETE,
url,
path_parameters=path_parameters,
Expand All @@ -131,7 +131,7 @@ def post_json(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_json_request(
return request_json(
Method.POST,
url,
data,
Expand Down Expand Up @@ -159,7 +159,7 @@ def put_json(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_json_request(
return request_json(
Method.PUT,
url,
data,
Expand Down Expand Up @@ -187,7 +187,7 @@ def patch_json(
allow_redirects: bool = True,
max_redirects: int = MAX_REDIRECTS,
) -> Request:
return build_json_request(
return request_json(
Method.PATCH,
url,
data,
Expand All @@ -202,7 +202,7 @@ def patch_json(
)


def build_json_request(
def request_json(
method: str,
url: str | yarl.URL,
data: Any,
Expand All @@ -221,7 +221,7 @@ def build_json_request(

body = dumps(data).encode(encoding)

return build_request(
return request(
method=method,
url=url,
headers=multidict.CIMultiDictProxy[str](enriched_headers),
Expand All @@ -233,7 +233,10 @@ def build_json_request(
)


def build_request(
build_json_request = request_json


def request(
method: str,
url: str | yarl.URL,
*,
Expand All @@ -254,3 +257,6 @@ def build_request(
allow_redirects=allow_redirects,
max_redirects=max_redirects,
)


build_request = request

0 comments on commit 33d7b81

Please sign in to comment.