pub struct RequestBuilder { /* private fields */ }Expand description
Builder for constructing test requests
Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn new(method: Method, path: &str, default_headers: &HeaderMap) -> Self
pub fn new(method: Method, path: &str, default_headers: &HeaderMap) -> Self
Create a new request builder with the given HTTP method, path, and default headers.
Sourcepub fn with_format(self, format: &str) -> Self
pub fn with_format(self, format: &str) -> Self
Set the content format for this request.
Sourcepub fn header(self, name: &str, value: &str) -> Result<Self, ClientError>
pub fn header(self, name: &str, value: &str) -> Result<Self, ClientError>
Add a custom HTTP header to this request builder.
Sourcepub fn query_param(self, key: &str, value: &str) -> Self
pub fn query_param(self, key: &str, value: &str) -> Self
Add a query parameter (alias for query).
Sourcepub fn json<T: Serialize>(self, data: &T) -> Result<Self, ClientError>
pub fn json<T: Serialize>(self, data: &T) -> Result<Self, ClientError>
Set request body as JSON
§Examples
use reinhardt_testkit::factory::APIRequestFactory;
use serde_json::json;
let factory = APIRequestFactory::new();
let data = json!({"name": "test"});
let request = factory.post("/api/users/").json(&data).unwrap().build();Sourcepub fn form<T: Serialize>(self, data: &T) -> Result<Self, ClientError>
pub fn form<T: Serialize>(self, data: &T) -> Result<Self, ClientError>
Set request body as form data
§Examples
use reinhardt_testkit::factory::APIRequestFactory;
use serde_json::json;
let factory = APIRequestFactory::new();
let data = json!({"name": "test", "age": 30});
let request = factory.post("/api/users/").form(&data).unwrap().build();Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
pub fn body(self, body: impl Into<Bytes>) -> Self
Set raw body
§Examples
use reinhardt_testkit::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.post("/api/upload/").body("raw data").build().unwrap();Sourcepub fn force_authenticate(self, user: Value) -> Self
👎Deprecated since 0.1.0-rc.16: use client.auth().session() or client.auth().jwt() instead
pub fn force_authenticate(self, user: Value) -> Self
use client.auth().session() or client.auth().jwt() instead
Force authenticate as user (for testing)
§Examples
use reinhardt_testkit::factory::APIRequestFactory;
use serde_json::json;
let factory = APIRequestFactory::new();
let user = json!({"id": 1, "username": "testuser"});
let request = factory.get("/api/profile/").force_authenticate(user).build().unwrap();Auto Trait Implementations§
impl !Freeze for RequestBuilder
impl RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl UnsafeUnpin for RequestBuilder
impl UnwindSafe for RequestBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more