Skip to content

Commit

Permalink
Expose methods to build requests (#288)
Browse files Browse the repository at this point in the history
* Expose methods to build requests

* Add to CHANGELOG
  • Loading branch information
Pliner authored Jan 9, 2025
1 parent b9b543d commit 780b6f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## unreleased

* [Increase metrics buckets precision](https://github.com/anna-money/aio-request/pull/287/)
* [Increase metrics buckets precision](https://github.com/anna-money/aio-request/pull/287)
* [Expose methods to build requests](https://github.com/anna-money/aio-request/pull/288)


## v0.2.0 (2025-01-09)
Expand Down
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 780b6f7

Please sign in to comment.