pub struct Response { /* private fields */ }
Expand description
Response builder for creating HTTP responses with fluent API
Implementations§
Source§impl ElifResponse
impl ElifResponse
Sourcepub fn new() -> ElifResponse
pub fn new() -> ElifResponse
Create new response with OK status
Sourcepub fn with_status(status: ElifStatusCode) -> ElifResponse
pub fn with_status(status: ElifStatusCode) -> ElifResponse
Create response with specific status code
Sourcepub fn status(self, status: ElifStatusCode) -> ElifResponse
pub fn status(self, status: ElifStatusCode) -> ElifResponse
Set response status code (consuming)
Sourcepub fn set_status(&mut self, status: ElifStatusCode)
pub fn set_status(&mut self, status: ElifStatusCode)
Set response status code (borrowing - for middleware use)
Sourcepub fn status_code(&self) -> ElifStatusCode
pub fn status_code(&self) -> ElifStatusCode
Get response status code
Sourcepub fn headers(&self) -> &ElifHeaderMap
pub fn headers(&self) -> &ElifHeaderMap
Get response headers
Sourcepub fn headers_mut(&mut self) -> &mut ElifHeaderMap
pub fn headers_mut(&mut self) -> &mut ElifHeaderMap
Get mutable reference to response headers
Sourcepub fn has_header<K>(&self, key: K) -> bool
pub fn has_header<K>(&self, key: K) -> bool
Check if response has a specific header
Sourcepub fn get_header<K>(&self, key: K) -> Option<&ElifHeaderValue>
pub fn get_header<K>(&self, key: K) -> Option<&ElifHeaderValue>
Get header value by name
Sourcepub fn with_header<K, V>(self, key: K, value: V) -> ElifResponse
pub fn with_header<K, V>(self, key: K, value: V) -> ElifResponse
Add header to response (Simple - never panics)
Simple equivalent: $response->header('X-Custom', 'value')
Returns 500 error response on invalid header names/values
Sourcepub fn with_json<T>(self, data: &T) -> ElifResponsewhere
T: Serialize,
pub fn with_json<T>(self, data: &T) -> ElifResponsewhere
T: Serialize,
Set JSON body (Simple - never panics)
Simple equivalent: $response->json($data)
Returns 500 error response on serialization failure
Sourcepub fn with_text<S>(self, content: S) -> ElifResponse
pub fn with_text<S>(self, content: S) -> ElifResponse
Set text body (Simple - never fails)
Simple equivalent: response($text)
Sourcepub fn with_html<S>(self, content: S) -> ElifResponse
pub fn with_html<S>(self, content: S) -> ElifResponse
Set HTML body with content-type (Simple - never fails)
Simple equivalent: response($html)->header('Content-Type', 'text/html')
Sourcepub fn header<K, V>(self, key: K, value: V) -> Result<ElifResponse, HttpError>
pub fn header<K, V>(self, key: K, value: V) -> Result<ElifResponse, HttpError>
Add header to response (consuming)
Sourcepub fn add_header<K, V>(&mut self, key: K, value: V) -> Result<(), HttpError>
pub fn add_header<K, V>(&mut self, key: K, value: V) -> Result<(), HttpError>
Add header to response (borrowing - for middleware use)
Sourcepub fn remove_header<K>(&mut self, key: K) -> Option<ElifHeaderValue>
pub fn remove_header<K>(&mut self, key: K) -> Option<ElifHeaderValue>
Remove header from response
Sourcepub fn content_type(self, content_type: &str) -> Result<ElifResponse, HttpError>
pub fn content_type(self, content_type: &str) -> Result<ElifResponse, HttpError>
Set Content-Type header (consuming)
Sourcepub fn set_content_type(&mut self, content_type: &str) -> Result<(), HttpError>
pub fn set_content_type(&mut self, content_type: &str) -> Result<(), HttpError>
Set Content-Type header (borrowing - for middleware use)
Sourcepub fn text<S>(self, text: S) -> ElifResponse
pub fn text<S>(self, text: S) -> ElifResponse
Set response body as text (consuming)
Sourcepub fn set_text<S>(&mut self, text: S)
pub fn set_text<S>(&mut self, text: S)
Set response body as text (borrowing - for middleware use)
Sourcepub fn bytes(self, bytes: Bytes) -> ElifResponse
pub fn bytes(self, bytes: Bytes) -> ElifResponse
Set response body as bytes (consuming)
Sourcepub fn set_bytes(&mut self, bytes: Bytes)
pub fn set_bytes(&mut self, bytes: Bytes)
Set response body as bytes (borrowing - for middleware use)
Sourcepub fn json<T>(self, data: &T) -> Result<ElifResponse, HttpError>where
T: Serialize,
pub fn json<T>(self, data: &T) -> Result<ElifResponse, HttpError>where
T: Serialize,
Set response body as JSON (consuming)
Sourcepub fn set_json<T>(&mut self, data: &T) -> Result<(), HttpError>where
T: Serialize,
pub fn set_json<T>(&mut self, data: &T) -> Result<(), HttpError>where
T: Serialize,
Set response body as JSON (borrowing - for middleware use)
Sourcepub fn json_value(self, value: Value) -> ElifResponse
pub fn json_value(self, value: Value) -> ElifResponse
Set response body as raw JSON value (consuming)
Sourcepub fn set_json_value(&mut self, value: Value)
pub fn set_json_value(&mut self, value: Value)
Set response body as raw JSON value (borrowing - for middleware use)
Source§impl ElifResponse
Convenience methods for common response types
impl ElifResponse
Convenience methods for common response types
Sourcepub fn ok() -> ElifResponse
pub fn ok() -> ElifResponse
Create 200 OK response
Sourcepub fn created() -> ElifResponse
pub fn created() -> ElifResponse
Create 201 Created response
Sourcepub fn no_content() -> ElifResponse
pub fn no_content() -> ElifResponse
Create 204 No Content response
Sourcepub fn bad_request() -> ElifResponse
pub fn bad_request() -> ElifResponse
Create 400 Bad Request response
Create 401 Unauthorized response
Sourcepub fn forbidden() -> ElifResponse
pub fn forbidden() -> ElifResponse
Create 403 Forbidden response
Sourcepub fn not_found() -> ElifResponse
pub fn not_found() -> ElifResponse
Create 404 Not Found response
Sourcepub fn unprocessable_entity() -> ElifResponse
pub fn unprocessable_entity() -> ElifResponse
Create 422 Unprocessable Entity response
Sourcepub fn internal_server_error() -> ElifResponse
pub fn internal_server_error() -> ElifResponse
Create 500 Internal Server Error response
Sourcepub fn json_ok<T>(data: &T) -> Result<Response<Body>, HttpError>where
T: Serialize,
pub fn json_ok<T>(data: &T) -> Result<Response<Body>, HttpError>where
T: Serialize,
Create JSON response with data
Sourcepub fn json_error(
status: ElifStatusCode,
message: &str,
) -> Result<Response<Body>, HttpError>
pub fn json_error( status: ElifStatusCode, message: &str, ) -> Result<Response<Body>, HttpError>
Create JSON error response
Source§impl ElifResponse
Redirect response builders
impl ElifResponse
Redirect response builders
Sourcepub fn redirect_permanent(location: &str) -> Result<ElifResponse, HttpError>
pub fn redirect_permanent(location: &str) -> Result<ElifResponse, HttpError>
Create 301 Moved Permanently redirect
Sourcepub fn redirect_temporary(location: &str) -> Result<ElifResponse, HttpError>
pub fn redirect_temporary(location: &str) -> Result<ElifResponse, HttpError>
Create 302 Found (temporary) redirect
Sourcepub fn redirect_see_other(location: &str) -> Result<ElifResponse, HttpError>
pub fn redirect_see_other(location: &str) -> Result<ElifResponse, HttpError>
Create 303 See Other redirect
Source§impl ElifResponse
File download response builders
impl ElifResponse
File download response builders
Sourcepub fn download(
filename: &str,
content: Bytes,
) -> Result<ElifResponse, HttpError>
pub fn download( filename: &str, content: Bytes, ) -> Result<ElifResponse, HttpError>
Create file download response
Sourcepub fn file_inline(
filename: &str,
content_type: &str,
content: Bytes,
) -> Result<ElifResponse, HttpError>
pub fn file_inline( filename: &str, content_type: &str, content: Bytes, ) -> Result<ElifResponse, HttpError>
Create inline file response (display in browser)
Source§impl ElifResponse
Enhanced response helper methods for common patterns
impl ElifResponse
Enhanced response helper methods for common patterns
Sourcepub fn json_with_status<T>(
status: ElifStatusCode,
data: &T,
) -> Result<ElifResponse, HttpError>where
T: Serialize,
pub fn json_with_status<T>(
status: ElifStatusCode,
data: &T,
) -> Result<ElifResponse, HttpError>where
T: Serialize,
Create JSON response with data and optional status
Sourcepub fn json_raw(value: Value) -> ElifResponse
pub fn json_raw(value: Value) -> ElifResponse
Create JSON response from serde_json::Value
Sourcepub fn json_raw_with_status(
status: ElifStatusCode,
value: Value,
) -> ElifResponse
pub fn json_raw_with_status( status: ElifStatusCode, value: Value, ) -> ElifResponse
Create JSON response from serde_json::Value with status
Sourcepub fn text_with_type(
content: &str,
content_type: &str,
) -> Result<ElifResponse, HttpError>
pub fn text_with_type( content: &str, content_type: &str, ) -> Result<ElifResponse, HttpError>
Create text response with custom content type
Sourcepub fn xml<S>(content: S) -> Result<ElifResponse, HttpError>
pub fn xml<S>(content: S) -> Result<ElifResponse, HttpError>
Create XML response
Sourcepub fn csv<S>(content: S) -> Result<ElifResponse, HttpError>
pub fn csv<S>(content: S) -> Result<ElifResponse, HttpError>
Create CSV response
Sourcepub fn javascript<S>(content: S) -> Result<ElifResponse, HttpError>
pub fn javascript<S>(content: S) -> Result<ElifResponse, HttpError>
Create JavaScript response
Sourcepub fn css<S>(content: S) -> Result<ElifResponse, HttpError>
pub fn css<S>(content: S) -> Result<ElifResponse, HttpError>
Create CSS response
Sourcepub fn stream() -> Result<ElifResponse, HttpError>
pub fn stream() -> Result<ElifResponse, HttpError>
Create streaming response with chunked transfer encoding
Sourcepub fn sse() -> Result<ElifResponse, HttpError>
pub fn sse() -> Result<ElifResponse, HttpError>
Create Server-Sent Events (SSE) response
Sourcepub fn jsonp<T>(callback: &str, data: &T) -> Result<ElifResponse, HttpError>where
T: Serialize,
pub fn jsonp<T>(callback: &str, data: &T) -> Result<ElifResponse, HttpError>where
T: Serialize,
Create JSONP response with callback
Sourcepub fn image(
content: Bytes,
format: ImageFormat,
) -> Result<ElifResponse, HttpError>
pub fn image( content: Bytes, format: ImageFormat, ) -> Result<ElifResponse, HttpError>
Create image response from bytes with format detection
Sourcepub fn binary(
content: Bytes,
mime_type: &str,
) -> Result<ElifResponse, HttpError>
pub fn binary( content: Bytes, mime_type: &str, ) -> Result<ElifResponse, HttpError>
Create binary response with custom MIME type
Sourcepub fn cors_preflight(
allowed_origins: &[&str],
allowed_methods: &[&str],
allowed_headers: &[&str],
max_age: Option<u32>,
) -> Result<ElifResponse, HttpError>
pub fn cors_preflight( allowed_origins: &[&str], allowed_methods: &[&str], allowed_headers: &[&str], max_age: Option<u32>, ) -> Result<ElifResponse, HttpError>
Create CORS preflight response
Sourcepub fn with_cors(
self,
origin: &str,
credentials: bool,
exposed_headers: Option<&[&str]>,
) -> Result<ElifResponse, HttpError>
pub fn with_cors( self, origin: &str, credentials: bool, exposed_headers: Option<&[&str]>, ) -> Result<ElifResponse, HttpError>
Add CORS headers to existing response
Sourcepub fn with_cache(
self,
max_age: u32,
public: bool,
) -> Result<ElifResponse, HttpError>
pub fn with_cache( self, max_age: u32, public: bool, ) -> Result<ElifResponse, HttpError>
Create response with caching headers
Sourcepub fn conditional(self, request_etag: Option<&str>) -> ElifResponse
pub fn conditional(self, request_etag: Option<&str>) -> ElifResponse
Create conditional response based on If-None-Match header
Sourcepub fn with_security_headers(self) -> Result<ElifResponse, HttpError>
pub fn with_security_headers(self) -> Result<ElifResponse, HttpError>
Add security headers to response
Sourcepub fn with_performance_headers(self) -> Result<ElifResponse, HttpError>
pub fn with_performance_headers(self) -> Result<ElifResponse, HttpError>
Add performance headers
Source§impl ElifResponse
Response transformation helpers
impl ElifResponse
Response transformation helpers
Sourcepub fn transform_body<F>(self, transform: F) -> ElifResponse
pub fn transform_body<F>(self, transform: F) -> ElifResponse
Transform response body with a closure
Sourcepub fn with_headers<I, K, V>(
self,
headers: I,
) -> Result<ElifResponse, HttpError>
pub fn with_headers<I, K, V>( self, headers: I, ) -> Result<ElifResponse, HttpError>
Add multiple headers at once
Sourcepub fn build_axum(self) -> Response<Body>
pub fn build_axum(self) -> Response<Body>
Create response and immediately build to Axum Response
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if response is successful (2xx status)
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
Check if response is a redirect (3xx status)
Sourcepub fn body_size_estimate(&self) -> usize
pub fn body_size_estimate(&self) -> usize
Get response body size estimate
Trait Implementations§
Source§impl Debug for ElifResponse
impl Debug for ElifResponse
Source§impl Default for ElifResponse
impl Default for ElifResponse
Source§fn default() -> ElifResponse
fn default() -> ElifResponse
Source§impl From<ResponseBuilder> for ElifResponse
Convert ResponseBuilder to ElifResponse
impl From<ResponseBuilder> for ElifResponse
Convert ResponseBuilder to ElifResponse
Source§fn from(builder: ResponseBuilder) -> ElifResponse
fn from(builder: ResponseBuilder) -> ElifResponse
Source§impl HttpAssertions for ElifResponse
impl HttpAssertions for ElifResponse
fn assert_ok(&self)
fn assert_status(&self, expected: ElifStatusCode)
fn assert_json_contains(&self, _key: &str, _value: &str)
Source§impl IntoElifResponse for ElifResponse
impl IntoElifResponse for ElifResponse
fn into_response(self) -> ElifResponse
Source§impl IntoResponse for ElifResponse
Convert ElifResponse to Axum Response
impl IntoResponse for ElifResponse
Convert ElifResponse to Axum Response
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Auto Trait Implementations§
impl !Freeze for ElifResponse
impl RefUnwindSafe for ElifResponse
impl Send for ElifResponse
impl Sync for ElifResponse
impl Unpin for ElifResponse
impl UnwindSafe for ElifResponse
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
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>
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>
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