Expand description
Web framework integrations.
This module provides optional integrations with popular Rust web frameworks. Enable the corresponding feature flag to use them:
actix-integrationfor Actix-webrocket-integrationfor Rocketaxum-integrationfor Axum Web framework integrations.
This module provides optional integrations with popular Rust web frameworks,
making it easier to use BrowserPool in your web applications.
§Available Integrations
| Framework | Feature Flag | Module |
|---|---|---|
| Actix-web | actix-integration | actix |
| Rocket | rocket-integration | rocket |
| Axum | axum-integration | axum |
§Enabling Integrations
Add the desired feature to your Cargo.toml:
[dependencies]
html2pdf-api = { version = "0.1", features = ["actix-integration"] }§Common Pattern
All integrations follow a similar pattern:
- Create a
BrowserPoolduring application startup - Convert to shared state using
into_shared() - Register with your framework’s state management
- Extract the pool in handlers and use
pool.get()
§Example (Generic Pattern)
ⓘ
use html2pdf_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Create pool
let pool = BrowserPool::builder()
.factory(Box::new(ChromeBrowserFactory::with_defaults()))
.build()?;
// 2. Warmup
pool.warmup().await?;
// 3. Convert to shared state
let shared_pool = pool.into_shared();
// 4. Pass to your web framework...
Ok(())
}