pub fn configure_routes(rocket: Rocket<Build>) -> Rocket<Build>Expand description
Configure all PDF routes.
Adds all pre-built handlers to the Rocket instance 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 rocket::launch;
use html2pdf_api::prelude::*;
use html2pdf_api::integrations::rocket::configure_routes;
#[launch]
async fn rocket() -> _ {
let pool = init_browser_pool().await
.expect("Failed to initialize browser pool");
rocket::build()
.manage(pool)
.configure(configure_routes)
}§Adding Custom Routes
You can combine configure_routes with additional routes:
ⓘ
use rocket::{get, routes};
#[get("/custom")]
fn my_custom_handler() -> &'static str { "custom" }
rocket::build()
.manage(pool)
.configure(configure_routes) // Pre-built routes
.mount("/", routes![my_custom_handler]) // Your routes§Custom Path Prefix
To mount routes under a prefix, use routes() directly:
ⓘ
use html2pdf_api::integrations::rocket::routes;
rocket::build()
.manage(pool)
.mount("/api/v1", routes())
// Routes will be: /api/v1/pdf, /api/v1/health, etc.