grafbase_sdk/types/
hooks.rs

1use crate::{types::Headers, wit};
2
3/// Represents the parts of an HTTP request, including the URL, method, and headers.
4#[non_exhaustive]
5pub struct HttpRequestParts {
6    /// The URL of the HTTP request.
7    pub url: String,
8    /// The HTTP method of the request, such as GET, POST, etc.
9    pub method: http::Method,
10    /// The headers of the HTTP request.
11    pub headers: Headers,
12}
13
14impl From<wit::HttpRequestParts> for HttpRequestParts {
15    fn from(parts: wit::HttpRequestParts) -> Self {
16        Self {
17            url: parts.url,
18            method: parts.method.into(),
19            headers: parts.headers.into(),
20        }
21    }
22}
23
24impl From<HttpRequestParts> for wit::HttpRequestParts {
25    fn from(parts: HttpRequestParts) -> Self {
26        Self {
27            url: parts.url,
28            method: parts.method.into(),
29            headers: parts.headers.into(),
30        }
31    }
32}
33
34/// Output type for the `on_request` hook.
35#[derive(Default)]
36pub struct OnRequestOutput {
37    pub(crate) contract_key: Option<String>,
38}
39
40impl OnRequestOutput {
41    /// Creates a new `OnRequestOutput` instance with default values.
42    pub fn new() -> Self {
43        Self::default()
44    }
45
46    /// Sets the contract key for the request.
47    pub fn contract_key(mut self, contract_key: String) -> Self {
48        self.contract_key = Some(contract_key);
49        self
50    }
51}