Skip to content

Introduce HTTP client adapter #78

@rafalkrupinski

Description

@rafalkrupinski

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
   """

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions