pub fn configure_routes(cfg: &mut ServiceConfig)Expand description
Configure all PDF routes.
Adds all pre-built handlers to the Actix-web app with default paths. This is the easiest way to set up the PDF service.
§Routes Added
| Method | Path | Handler | Description |
|---|---|---|---|
| GET | /pdf | pdf_from_url | Convert URL to PDF |
| POST | /pdf/html | pdf_from_html | Convert HTML to PDF |
| GET | /pool/stats | pool_stats | Pool statistics |
| GET | /health | health_check | Health check |
| GET | /ready | readiness_check | Readiness check |
§Example
ⓘ
use actix_web::{App, HttpServer, web};
use html2pdf_api::prelude::*;
use html2pdf_api::integrations::actix::configure_routes;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = init_browser_pool().await?;
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.configure(configure_routes)
})
.bind("127.0.0.1:8080")?
.run()
.await
}§Adding Custom Routes
You can combine configure_routes with additional routes:
ⓘ
App::new()
.app_data(web::Data::new(pool.clone()))
.configure(configure_routes) // Pre-built routes
.route("/custom", web::get().to(my_custom_handler)) // Your routes§Custom Path Prefix
To mount routes under a prefix, use web::scope:
ⓘ
App::new()
.app_data(web::Data::new(pool.clone()))
.service(
web::scope("/api/v1")
.configure(configure_routes)
)
// Routes will be: /api/v1/pdf, /api/v1/health, etc.