pub struct APIRequestFactory { /* private fields */ }Expand description
Factory for creating test requests
Implementations§
Source§impl APIRequestFactory
impl APIRequestFactory
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new request factory
§Examples
use reinhardt_test::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.get("/api/users/").build();pub fn with_format(self, format: impl Into<String>) -> Self
pub fn with_header( self, name: impl AsRef<str>, value: impl AsRef<str>, ) -> Result<Self, ClientError>
Sourcepub fn get(&self, path: &str) -> RequestBuilder
pub fn get(&self, path: &str) -> RequestBuilder
Create a GET request
§Examples
use reinhardt_test::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.get("/api/users/").build().unwrap();
assert_eq!(request.method(), "GET");Sourcepub fn post(&self, path: &str) -> RequestBuilder
pub fn post(&self, path: &str) -> RequestBuilder
Create a POST request
§Examples
use reinhardt_test::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().unwrap();
assert_eq!(request.method(), "POST");Sourcepub fn put(&self, path: &str) -> RequestBuilder
pub fn put(&self, path: &str) -> RequestBuilder
Create a PUT request
§Examples
use reinhardt_test::factory::APIRequestFactory;
use serde_json::json;
let factory = APIRequestFactory::new();
let data = json!({"name": "updated"});
let request = factory.put("/api/users/1/").json(&data).unwrap().build().unwrap();
assert_eq!(request.method(), "PUT");Sourcepub fn patch(&self, path: &str) -> RequestBuilder
pub fn patch(&self, path: &str) -> RequestBuilder
Create a PATCH request
§Examples
use reinhardt_test::factory::APIRequestFactory;
use serde_json::json;
let factory = APIRequestFactory::new();
let data = json!({"name": "partial_update"});
let request = factory.patch("/api/users/1/").json(&data).unwrap().build().unwrap();
assert_eq!(request.method(), "PATCH");Sourcepub fn delete(&self, path: &str) -> RequestBuilder
pub fn delete(&self, path: &str) -> RequestBuilder
Create a DELETE request
§Examples
use reinhardt_test::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.delete("/api/users/1/").build().unwrap();
assert_eq!(request.method(), "DELETE");Sourcepub fn head(&self, path: &str) -> RequestBuilder
pub fn head(&self, path: &str) -> RequestBuilder
Create a HEAD request
§Examples
use reinhardt_test::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.head("/api/users/").build().unwrap();
assert_eq!(request.method(), "HEAD");Sourcepub fn options(&self, path: &str) -> RequestBuilder
pub fn options(&self, path: &str) -> RequestBuilder
Create an OPTIONS request
§Examples
use reinhardt_test::factory::APIRequestFactory;
let factory = APIRequestFactory::new();
let request = factory.options("/api/users/").build().unwrap();
assert_eq!(request.method(), "OPTIONS");Sourcepub fn request(&self, method: Method, path: &str) -> RequestBuilder
pub fn request(&self, method: Method, path: &str) -> RequestBuilder
Create a generic request with custom method
§Examples
use reinhardt_test::factory::APIRequestFactory;
use http::Method;
let factory = APIRequestFactory::new();
let request = factory.request(Method::TRACE, "/api/trace/").build().unwrap();
assert_eq!(request.method(), "TRACE");Trait Implementations§
Auto Trait Implementations§
impl Freeze for APIRequestFactory
impl RefUnwindSafe for APIRequestFactory
impl Send for APIRequestFactory
impl Sync for APIRequestFactory
impl Unpin for APIRequestFactory
impl UnsafeUnpin for APIRequestFactory
impl UnwindSafe for APIRequestFactory
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().