Comments (3)
Both underlying libraries aiohttp
and httpx
support timeout
for both verbs so would make sense to have support in both.
from aiodynamo.
get
is used by credentials which has a different timeout logic than post
which is used in combination with ThrottleConfig
. I think that's why those are different.
To be honest, I think the whole aiodynamo.http.base.HTTP
interface was a mistake (at least the way it was implemented). I still think that not tying aiodynamo tightly to a specific http library/version is a good goal (since those usually move quite fast and version conflicts would be quite probable), but the interface is terrible. The API disparity between get
and post
is a good example of that. It kind of makes sense if you look at the call sites why they return different things, but it's just confusing.
I think the actual interface for pluggable HTTP should be something more like the following and maybe it should be changed to that. Then, the timeout logic and handling dynamo-level errors (400s, exception_from_response
) could be handled internally and the http-glue code doesn't have to worry about it:
from dataclasses import dataclass
from typing import Optional, Callable, Awaitable, Literal, Union, Dict
import aiohttp
import httpx
@dataclass(frozen=True)
class Request:
method: Union[Literal["GET"], Literal["POST"]]
url: str
headers: Dict[str, str] # Mapping is more appropriate but httpx doesn't like it...
body: Optional[bytes]
@dataclass(frozen=True)
class Response:
status: int
body: bytes # may be empty bytes
@dataclass
class RequestFailed(Exception):
inner: Exception
HTTPInterface = Callable[
[Request], Awaitable[Response]
] # may throw RequestFailed for connection based errors.
# Example implementations, actual implementations would likely be a class with an async __call__ so sessions etc
# can be re-used, for simplicity, that is ignored here.
async def aiohttp_impl(request: Request) -> Response:
session: aiohttp.ClientSession
try:
async with session.request(
method=request.method,
url=request.url,
headers=request.headers,
body=request.body,
) as response:
return Response(response.status, await response.read())
except aiohttp.ClientError as exc:
raise RequestFailed(exc)
async def httpx_impl(request: Request) -> Response:
client: httpx.AsyncClient
try:
response = await client.request(
method=request.method,
url=request.url,
headers=request.headers,
content=request.body,
)
return Response(response.status_code, await response.aread())
except httpx.HTTPError as exc:
raise RequestFailed(exc)
Would that be better and would this change be worth it?
from aiodynamo.
I quite like it!
Now is a good time to consider breaking changes, since 2022 is coming up and that changes the major version :)
from aiodynamo.
Related Issues (20)
- Http wrapping issues HOT 6
- F should implement __eq__ and __repr__
- 21.12 breaks some apis HOT 2
- Maybe summarise how DynamoDB works
- FileCredentials never set aws_session_token HOT 1
- Incompatible argument type issues after version 22.2 HOT 2
- KeyConditionExpression does not allow IN
- Support for applications running on Kubernetes
- after moving to github actions, integration tests are no longer run
- Add Amazon DynamoDB Accelerator (DAX) support to the library HOT 3
- Surprising behaviour in `Client.table_exists` HOT 1
- Auth Error With No Default Credentials HOT 1
- Unable to use AWS_REGION env var HOT 3
- Support AWS Web Identity Token File authentication HOT 2
- Shall we try goodfirstissue.dev ?
- Empty-set safety HOT 3
- Session instantiation HOT 6
- Get most recently added entry HOT 5
- ECS Fargate Credentials Compatibility HOT 2
- Support for typing-extensions version 4 module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiodynamo.