configure_routes

Function configure_routes 

Source
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

MethodPathHandlerDescription
GET/pdfpdf_from_urlConvert URL to PDF
POST/pdf/htmlpdf_from_htmlConvert HTML to PDF
GET/pool/statspool_statsPool statistics
GET/healthhealth_checkHealth check
GET/readyreadiness_checkReadiness 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.