Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce HTTP client adapter #78

Open
rafalkrupinski opened this issue Oct 17, 2024 · 0 comments
Open

Introduce HTTP client adapter #78

rafalkrupinski opened this issue Oct 17, 2024 · 0 comments
Assignees

Comments

@rafalkrupinski
Copy link
Contributor

The problem

Currently Lapidary supports only httpx and it's rather tightly integrated with it. The tight integration makes it hard to replace the underlying http client (#77) and impossible for users to introduce any customizations.

Solution

HTTP client adapter will be a component that conceptually sits between data serializer and http client, the whole being wrapped and managed by the ClientBase instance.

Lapidary really just converts python data into HTTP method, raw headers and request body, calls HTTP client and converts status code, raw headers and response body back to python objects.

Since adapter would provide an API purely for internal Lapidary use, it wouldn't need any facility methods like post, get and so on; a single method like exchange would suffice.

class Request(NamedTuple):
  method: str
  headers: list[tuple[str, str]]
  content: AsyncIterator[bytes]
  ssl: SSLContext
class Response(NamedTuple):
  status_code: int
  headers: list[tuple[str, str]]
  content: AsyncIterator[bytes]
class HTTPConnectionError(Error):pass
async def exchange(request: Request)->Response:
   """
raises:
       HTTPConnectionError: general error for when a HTTP response couldn't be obtained
   """
@rafalkrupinski rafalkrupinski self-assigned this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant