configure_routes

Function configure_routes 

Source
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

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 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.