Skip to main content

modo/webhook/
client.rs

1use bytes::Bytes;
2use http::{HeaderMap, StatusCode};
3
4use crate::error::{Error, Result};
5
6/// Response returned after a webhook delivery attempt.
7pub struct WebhookResponse {
8    /// HTTP status code returned by the endpoint.
9    pub status: StatusCode,
10    /// Response body bytes.
11    pub body: Bytes,
12}
13
14/// Send a webhook POST via the shared HTTP client.
15pub(crate) async fn post(
16    client: &reqwest::Client,
17    url: &str,
18    headers: HeaderMap,
19    body: Bytes,
20) -> Result<WebhookResponse> {
21    let response = client
22        .post(url)
23        .headers(headers)
24        .body(body)
25        .send()
26        .await
27        .map_err(|e| Error::internal("webhook delivery failed").chain(e))?;
28    let status = response.status();
29    let response_body = response
30        .bytes()
31        .await
32        .map_err(|e| Error::internal("failed to read webhook response").chain(e))?;
33
34    Ok(WebhookResponse {
35        status,
36        body: response_body,
37    })
38}