I'm a programmer.
Hi there 👋
I am an college student who tries various fields of programming.
A framework for easy asynchronous HTTP request calling with decorations
Home Page: https://pypi.org/p/ahttp-client
License: MIT License
I'm a programmer.
Hi there 👋
I am an college student who tries various fields of programming.
Support typing.Annotated
for add request component
from async_client_decorator import get, Session, Query
from typing import Annotated
@Session.single_session("https://base_url")
@get("/")
async def request(response: aiohttp.ClientResponse, parameter: Annotated[str, Query]):
...
For convenience, support Union Type(Multiple Type) at request component.
from async_client_decorator import get, Session, Query
from typing import Annotated
@Session.single_session("https://base_url")
@get("/")
async def request(response: aiohttp.ClientResponse, parameter: str | Query):
...
_request
methodSupport Custom Name at Header, Parameter or Path.
According to PEP rules, function parameter name must be snake_case.
If API parameter name is camel case, it violates the PEP rules
Not Started
Support Pydantic data model at wrapper
# Example
# ----------
@app.get("/station/<name>")
@Session.single_session("https://api.yhs.kr")
@request("GET", "/bus/station")
async def station_search_with_query(
session: Session
) -> PydanticModel:
pass # return validated PydanticModel
``
The return type of a method decorated with _request
method cannot support union type
Set return annotation of the request method to Union Type.
import aiohttp
from async_client_decorator import *
class TSession(Session):
def __init__(self, api_key: str):
self.api_key = api_key
super().__init__(
base_url="https://based_url/",
headers={
"Authorization": "Bearer {0}".format(self.api_key),
}
)
@get("/{block_id}/")
async def retrieve_block_children(
self,
response: aiohttp.ClientResponse,
block_id: Path | str
) -> list[block.BLOCKS] | None: # Casued Issue
pass
Nothing, only success compile.
Cuased compile error
Traceback (most recent call last):
File "%CONSOLE_PATH%", line 367, in runcode
loop.run_until_complete(coro)
File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "<input>", line 3, in <module>
File "%PROJECT_PATH%\venv_p\Lib\site-packages\async_client_decorator\request.py", line 161, in wrapper
issubclass(signature.return_annotation, aiohttp.ClientResponse)
TypeError: issubclass() arg 1 must be a class
Software:
Hardware:
Inheritence aiohttp.ClientSession
was not allowed. (aiohttp/#2691)
Except TypeError
, when generic type used in method
...
@Session.single_session("BASE_URL")
@request("GET", "/")
async def test_method(
session: Session, response: aiohttp.ClientResponse, name: list[str] | Body
^^^^^
) -> list[...]:
...
set_body
method in component.py
Instead of decorating wrapper, use the Request
object
To possible to manage pre-call wrapper and post-call wrapper with decorating.
For example
@app.get("/station/<name>")
@Session.single_session("https://api.yhs.kr")
@request("GET", "/bus/station")
async def station_search_with_query(
session: Session, response: aiohttp.ClientResponse, name: Query | str
):
return await response.json()
# If need to manage requests before request HTTP Client
@station_search_with_query.before_call
async def before_call( ... ):
pass
requests.py
before_call
, after_http_call
and after_call
method
before_call
decorating function (For dynamic request component)after_http_call
decorating function (To edit parameter, for wrapper)after_call
decorating function (Success API Called)This release may be a major update. (v1.0.0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.