actix_web::test

Function call_service

source
pub async fn call_service<S, R, B, E>(app: &S, req: R) -> S::Response
where S: Service<R, Response = ServiceResponse<B>, Error = E>, E: Debug,
Expand description

Calls service and waits for response future completion.

§Examples

use actix_web::{test, web, App, HttpResponse, http::StatusCode};

#[actix_web::test]
async fn test_response() {
    let app = test::init_service(
        App::new()
            .service(web::resource("/test").to(|| async {
                HttpResponse::Ok()
            }))
    ).await;

    // Create request object
    let req = test::TestRequest::with_uri("/test").to_request();

    // Call application
    let res = test::call_service(&app, req).await;
    assert_eq!(res.status(), StatusCode::OK);
}

§Panics

Panics if service call returns error. To handle errors use app.call(req).