Skip to content

feat: Add support for custom http clients#146

Merged
drish merged 7 commits intomainfrom
feat/custom-http-client
Jul 7, 2025
Merged

feat: Add support for custom http clients#146
drish merged 7 commits intomainfrom
feat/custom-http-client

Conversation

@drish
Copy link
Member

@drish drish commented May 26, 2025

Introduced a new global level attribute default_http_client, that can be overwritten by users to set their own HTTP Clients. Custom clients need to base off the "interface" HTTPClient defined in resend/http_client.py

Example:

# resend's abstract HTTP Client class.
from resend.http_client import HTTPClient

class CustomRequestsClient(HTTPClient):
    def __init__(self, timeout: int = 30):
        self.timeout = timeout

    def request(
        self,
        method: str,
        url: str,
        headers: Mapping[str, str],
        json: Optional[Union[Dict[str, Any], List[Any]]] = None,
    ) -> Tuple[bytes, int, Dict[str, str]]:
        print(f"[HTTP] {method.upper()} {url} with timeout={self.timeout}")
        try:
            response = requests.request(
                method=method,
                url=url,
                headers=headers,
                json=json,
                timeout=self.timeout,
            )
            return (
                response.content,
                response.status_code,
                dict(response.headers),
            )
        except requests.RequestException as e:
            raise RuntimeError(f"HTTP request failed: {e}") from e


resend.api_key = "re_123"
resend.default_http_client = CustomRequestsClient(timeout=400)

email: resend.Email = resend.Emails.send({...})

closes #145

@graphite-app
Copy link

graphite-app bot commented May 26, 2025

How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@drish drish marked this pull request as ready for review May 27, 2025 00:01
@drish drish requested a review from felipevolpone May 27, 2025 00:01
@drish drish changed the title feat: Add support for custom http client feat: Add support for custom http clients May 27, 2025
@drish drish requested review from Cisneiros and bukinoshita June 26, 2025 18:17
@drish drish merged commit edfae84 into main Jul 7, 2025
19 checks passed
@drish drish deleted the feat/custom-http-client branch July 7, 2025 17:46
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

Successfully merging this pull request may close these issues.

Request timeout needed

2 participants