Macro actix_web_lab::test_request

source ·
macro_rules! test_request {
    ($method:ident $uri:expr) => { ... };
    ($method:ident $uri:expr; $($hdr_name:expr => $hdr_val:expr)+) => { ... };
    ($method:ident $uri:expr; $($hdr_name:expr => $hdr_val:expr)+; @json $payload:tt) => { ... };
    ($method:ident $uri:expr; $($hdr_name:expr => $hdr_val:expr)+; @raw $payload:expr) => { ... };
}
Expand description

Create a TestRequest using a DSL that looks kinda like on-the-wire HTTP/1.x requests.

§Examples

use actix_web::test::TestRequest;
use actix_web_lab::test_request;

let _req: TestRequest = test_request! {
    POST "/";
    "Origin" => "example.com"
    "Access-Control-Request-Method" => "POST"
    "Access-Control-Request-Headers" => "Content-Type, X-CSRF-TOKEN";
    @json {"abc": "123"}
};

let _req: TestRequest = test_request! {
    POST "/";
    "Content-Type" => "application/json"
    "Origin" => "example.com"
    "Access-Control-Request-Method" => "POST"
    "Access-Control-Request-Headers" => "Content-Type, X-CSRF-TOKEN";
    @raw r#"{"abc": "123"}"#
};