Actix-web not extracting data from handler if config is added to app

hello. I have this code that works fine:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    dotenv().ok();
    let client = web::Data::new(prisma::new_client().await.unwrap());

    HttpServer::new(move || {
        App::new()
            .app_data(client.clone())
            .service(get_books)
    })
    .bind(("127.0.0.1", 4000))?
    .run()
    .await
}

but I get this error:

DEBUG actix_web::data] Failed to extract `Data<rust_gql_server::prisma::_prisma::PrismaClient>` for `/get_books` handler. For the Data extractor to work correctly, wrap the data with `Data::new()` and pass it to `App::app_data()`. Ensure that types align in both the set and retrieve calls.

when I change it to this, which is how I eventually would like it to be defined:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    dotenv().ok();
    let client = web::Data::new(prisma::new_client().await.unwrap());

    HttpServer::new(move || {
        App::new()
            .app_data(client.clone())
            .configure(endpoints) // <--- only change is switching service to this and the service will be added to endpoints config
    })
    .bind(("127.0.0.1", 4000))?
    .run()
    .await
}

I can provide more code on request but I thought just showing this might be enough. Any help on fixing this is appreciated. Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.