pub struct ResponseFactory { /* private fields */ }Expand description
Factory for creating test HTTP responses.
§Example
ⓘ
use fastapi_core::fixtures::ResponseFactory;
// Simple 200 OK
let resp = ResponseFactory::ok().build();
// JSON response
let resp = ResponseFactory::ok()
.json(&user)
.build();
// Error response
let resp = ResponseFactory::not_found()
.json(&ErrorBody { message: "User not found" })
.build();Implementations§
Source§impl ResponseFactory
impl ResponseFactory
Sourcepub fn new(status: StatusCode) -> Self
pub fn new(status: StatusCode) -> Self
Create a new response factory with the given status code.
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Create a 204 No Content response factory.
Sourcepub fn moved_permanently(location: impl AsRef<str>) -> Self
pub fn moved_permanently(location: impl AsRef<str>) -> Self
Create a 301 Moved Permanently response factory.
Sourcepub fn bad_request() -> Self
pub fn bad_request() -> Self
Create a 400 Bad Request response factory.
Create a 401 Unauthorized response factory.
Sourcepub fn unprocessable_entity() -> Self
pub fn unprocessable_entity() -> Self
Create a 422 Unprocessable Entity response factory.
Sourcepub fn internal_server_error() -> Self
pub fn internal_server_error() -> Self
Create a 500 Internal Server Error response factory.
Sourcepub fn status(self, status: StatusCode) -> Self
pub fn status(self, status: StatusCode) -> Self
Set the status code.
Sourcepub fn content_type(self, content_type: impl AsRef<str>) -> Self
pub fn content_type(self, content_type: impl AsRef<str>) -> Self
Set the Content-Type header.
Trait Implementations§
Source§impl Clone for ResponseFactory
impl Clone for ResponseFactory
Source§fn clone(&self) -> ResponseFactory
fn clone(&self) -> ResponseFactory
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ResponseFactory
impl RefUnwindSafe for ResponseFactory
impl Send for ResponseFactory
impl Sync for ResponseFactory
impl Unpin for ResponseFactory
impl UnwindSafe for ResponseFactory
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).