Skip to main content

cratefield_core/ports/
http.rs

1//! The `HttpClient` port (architecture section 5): plain `http` types over
2//! bytes, so adapters (Resend, Turnstile) run unchanged on Workers
3//! (`worker::Fetch`) and native (`reqwest`, phase 3).
4
5use async_trait::async_trait;
6use bytes::Bytes;
7use thiserror::Error;
8
9#[derive(Debug, Clone, Error)]
10pub enum HttpError {
11    #[error("http request failed: {0}")]
12    Transport(String),
13}
14
15#[async_trait]
16pub trait HttpClient: Send + Sync {
17    async fn send(&self, request: http::Request<Bytes>)
18    -> Result<http::Response<Bytes>, HttpError>;
19}