pub struct NotificaClient { /* private fields */ }Expand description
Async HTTP client for the Notifica webhook API.
Create one instance per application (it holds an internal connection pool) and reuse it for all notifications.
§Example
use notifica_crate::{EmailPayload, Notification, NotificaClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = NotificaClient::new("http://localhost:8000", "my-tenant");
client.send(
"user_registered",
Notification::new()
.email(EmailPayload::new("alice@example.com").subject("Welcome!")),
).await?;
Ok(())
}Implementations§
Source§impl NotificaClient
impl NotificaClient
Sourcepub fn new(base_url: impl Into<String>, tenant_id: impl Into<String>) -> Self
pub fn new(base_url: impl Into<String>, tenant_id: impl Into<String>) -> Self
Create a client with default reqwest::Client settings.
Panics if base_url or tenant_id is empty.
Sourcepub fn with_http_client(
base_url: impl Into<String>,
tenant_id: impl Into<String>,
http: Client,
) -> Self
pub fn with_http_client( base_url: impl Into<String>, tenant_id: impl Into<String>, http: Client, ) -> Self
Create a client with a custom reqwest::Client.
Use this when you need custom timeouts, TLS settings, or middleware.
Sourcepub async fn send(
&self,
event_name: impl Into<String>,
notification: Notification,
) -> NotificaResult<()>
pub async fn send( &self, event_name: impl Into<String>, notification: Notification, ) -> NotificaResult<()>
Send a notification to the given event name.
Calls POST {base_url}/webhook/{tenant_id}/{event_name} with the
serialized Notification as the JSON body.
Returns Ok(()) on a 200 response. Any other status code is
treated as NotificaError::UnexpectedResponse.
Auto Trait Implementations§
impl Freeze for NotificaClient
impl !RefUnwindSafe for NotificaClient
impl Send for NotificaClient
impl Sync for NotificaClient
impl Unpin for NotificaClient
impl UnsafeUnpin for NotificaClient
impl !UnwindSafe for NotificaClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more