pub struct ElifResponse { /* private fields */ }
Expand description
Response builder for creating HTTP responses with fluent API
Implementations§
Source§impl ElifResponse
impl ElifResponse
Sourcepub fn with_status(status: ElifStatusCode) -> Self
pub fn with_status(status: ElifStatusCode) -> Self
Create response with specific status code
Sourcepub fn status(self, status: ElifStatusCode) -> Self
pub fn status(self, status: ElifStatusCode) -> Self
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: AsRef<str>>(&self, key: K) -> bool
pub fn has_header<K: AsRef<str>>(&self, key: K) -> bool
Check if response has a specific header
Sourcepub fn get_header<K: AsRef<str>>(&self, key: K) -> Option<&ElifHeaderValue>
pub fn get_header<K: AsRef<str>>(&self, key: K) -> Option<&ElifHeaderValue>
Get header value by name
Sourcepub fn with_header<K, V>(self, key: K, value: V) -> Self
pub fn with_header<K, V>(self, key: K, value: V) -> Self
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: Serialize>(self, data: &T) -> Self
pub fn with_json<T: Serialize>(self, data: &T) -> Self
Set JSON body (Simple - never panics)
Simple equivalent: $response->json($data)
Returns 500 error response on serialization failure
Sourcepub fn with_text<S: AsRef<str>>(self, content: S) -> Self
pub fn with_text<S: AsRef<str>>(self, content: S) -> Self
Set text body (Simple - never fails)
Simple equivalent: response($text)
Sourcepub fn with_html<S: AsRef<str>>(self, content: S) -> Self
pub fn with_html<S: AsRef<str>>(self, content: S) -> Self
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) -> HttpResult<Self>
pub fn header<K, V>(self, key: K, value: V) -> HttpResult<Self>
Add header to response (consuming)
Sourcepub fn add_header<K, V>(&mut self, key: K, value: V) -> HttpResult<()>
pub fn add_header<K, V>(&mut self, key: K, value: V) -> HttpResult<()>
Add header to response (borrowing - for middleware use)
Sourcepub fn remove_header<K: AsRef<str>>(
&mut self,
key: K,
) -> Option<ElifHeaderValue>
pub fn remove_header<K: AsRef<str>>( &mut self, key: K, ) -> Option<ElifHeaderValue>
Remove header from response
Sourcepub fn content_type(self, content_type: &str) -> HttpResult<Self>
pub fn content_type(self, content_type: &str) -> HttpResult<Self>
Set Content-Type header (consuming)
Sourcepub fn set_content_type(&mut self, content_type: &str) -> HttpResult<()>
pub fn set_content_type(&mut self, content_type: &str) -> HttpResult<()>
Set Content-Type header (borrowing - for middleware use)
Sourcepub fn set_text<S: Into<String>>(&mut self, text: S)
pub fn set_text<S: Into<String>>(&mut self, text: S)
Set response body as text (borrowing - for middleware use)
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: Serialize>(self, data: &T) -> HttpResult<Self>
pub fn json<T: Serialize>(self, data: &T) -> HttpResult<Self>
Set response body as JSON (consuming)
Sourcepub fn set_json<T: Serialize>(&mut self, data: &T) -> HttpResult<()>
pub fn set_json<T: Serialize>(&mut self, data: &T) -> HttpResult<()>
Set response body as JSON (borrowing - for middleware use)
Sourcepub fn json_value(self, value: Value) -> Self
pub fn json_value(self, value: Value) -> Self
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)
Sourcepub fn build(self) -> HttpResult<Response<Body>>
pub fn build(self) -> HttpResult<Response<Body>>
Build the response
Source§impl ElifResponse
Convenience methods for common response types
impl ElifResponse
Convenience methods for common response types
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Create 204 No Content response
Sourcepub fn bad_request() -> Self
pub fn bad_request() -> Self
Create 400 Bad Request response
Create 401 Unauthorized response
Sourcepub fn unprocessable_entity() -> Self
pub fn unprocessable_entity() -> Self
Create 422 Unprocessable Entity response
Sourcepub fn internal_server_error() -> Self
pub fn internal_server_error() -> Self
Create 500 Internal Server Error response
Sourcepub fn json_ok<T: Serialize>(data: &T) -> HttpResult<Response<Body>>
pub fn json_ok<T: Serialize>(data: &T) -> HttpResult<Response<Body>>
Create JSON response with data
Sourcepub fn json_error(
status: ElifStatusCode,
message: &str,
) -> HttpResult<Response<Body>>
pub fn json_error( status: ElifStatusCode, message: &str, ) -> HttpResult<Response<Body>>
Create JSON error response
Sourcepub fn validation_error<T: Serialize>(errors: &T) -> HttpResult<Response<Body>>
pub fn validation_error<T: Serialize>(errors: &T) -> HttpResult<Response<Body>>
Create validation error response
Source§impl ElifResponse
Redirect response builders
impl ElifResponse
Redirect response builders
Sourcepub fn redirect_permanent(location: &str) -> HttpResult<Self>
pub fn redirect_permanent(location: &str) -> HttpResult<Self>
Create 301 Moved Permanently redirect
Sourcepub fn redirect_temporary(location: &str) -> HttpResult<Self>
pub fn redirect_temporary(location: &str) -> HttpResult<Self>
Create 302 Found (temporary) redirect
Sourcepub fn redirect_see_other(location: &str) -> HttpResult<Self>
pub fn redirect_see_other(location: &str) -> HttpResult<Self>
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) -> HttpResult<Self>
pub fn download(filename: &str, content: Bytes) -> HttpResult<Self>
Create file download response
Sourcepub fn file_inline(
filename: &str,
content_type: &str,
content: Bytes,
) -> HttpResult<Self>
pub fn file_inline( filename: &str, content_type: &str, content: Bytes, ) -> HttpResult<Self>
Create inline file response (display in browser)
Sourcepub fn file<P: AsRef<Path>>(path: P) -> HttpResult<Self>
pub fn file<P: AsRef<Path>>(path: P) -> HttpResult<Self>
Create file response from filesystem path
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: Serialize>(
status: ElifStatusCode,
data: &T,
) -> HttpResult<Self>
pub fn json_with_status<T: Serialize>( status: ElifStatusCode, data: &T, ) -> HttpResult<Self>
Create JSON response with data and optional status
Sourcepub fn json_raw_with_status(status: ElifStatusCode, value: Value) -> Self
pub fn json_raw_with_status(status: ElifStatusCode, value: Value) -> Self
Create JSON response from serde_json::Value with status
Sourcepub fn text_with_type(content: &str, content_type: &str) -> HttpResult<Self>
pub fn text_with_type(content: &str, content_type: &str) -> HttpResult<Self>
Create text response with custom content type
Sourcepub fn xml<S: AsRef<str>>(content: S) -> HttpResult<Self>
pub fn xml<S: AsRef<str>>(content: S) -> HttpResult<Self>
Create XML response
Sourcepub fn csv<S: AsRef<str>>(content: S) -> HttpResult<Self>
pub fn csv<S: AsRef<str>>(content: S) -> HttpResult<Self>
Create CSV response
Sourcepub fn javascript<S: AsRef<str>>(content: S) -> HttpResult<Self>
pub fn javascript<S: AsRef<str>>(content: S) -> HttpResult<Self>
Create JavaScript response
Sourcepub fn css<S: AsRef<str>>(content: S) -> HttpResult<Self>
pub fn css<S: AsRef<str>>(content: S) -> HttpResult<Self>
Create CSS response
Sourcepub fn stream() -> HttpResult<Self>
pub fn stream() -> HttpResult<Self>
Create streaming response with chunked transfer encoding
Sourcepub fn sse() -> HttpResult<Self>
pub fn sse() -> HttpResult<Self>
Create Server-Sent Events (SSE) response
Sourcepub fn jsonp<T: Serialize>(callback: &str, data: &T) -> HttpResult<Self>
pub fn jsonp<T: Serialize>(callback: &str, data: &T) -> HttpResult<Self>
Create JSONP response with callback
Sourcepub fn image(content: Bytes, format: ImageFormat) -> HttpResult<Self>
pub fn image(content: Bytes, format: ImageFormat) -> HttpResult<Self>
Create image response from bytes with format detection
Sourcepub fn binary(content: Bytes, mime_type: &str) -> HttpResult<Self>
pub fn binary(content: Bytes, mime_type: &str) -> HttpResult<Self>
Create binary response with custom MIME type
Sourcepub fn cors_preflight(
allowed_origins: &[&str],
allowed_methods: &[&str],
allowed_headers: &[&str],
max_age: Option<u32>,
) -> HttpResult<Self>
pub fn cors_preflight( allowed_origins: &[&str], allowed_methods: &[&str], allowed_headers: &[&str], max_age: Option<u32>, ) -> HttpResult<Self>
Create CORS preflight response
Sourcepub fn with_cors(
self,
origin: &str,
credentials: bool,
exposed_headers: Option<&[&str]>,
) -> HttpResult<Self>
pub fn with_cors( self, origin: &str, credentials: bool, exposed_headers: Option<&[&str]>, ) -> HttpResult<Self>
Add CORS headers to existing response
Sourcepub fn with_cache(self, max_age: u32, public: bool) -> HttpResult<Self>
pub fn with_cache(self, max_age: u32, public: bool) -> HttpResult<Self>
Create response with caching headers
Sourcepub fn conditional(self, request_etag: Option<&str>) -> Self
pub fn conditional(self, request_etag: Option<&str>) -> Self
Create conditional response based on If-None-Match header
Sourcepub fn with_security_headers(self) -> HttpResult<Self>
pub fn with_security_headers(self) -> HttpResult<Self>
Add security headers to response
Sourcepub fn with_performance_headers(self) -> HttpResult<Self>
pub fn with_performance_headers(self) -> HttpResult<Self>
Add performance headers
Source§impl ElifResponse
Response transformation helpers
impl ElifResponse
Response transformation helpers
Sourcepub fn transform_body<F>(self, transform: F) -> Self
pub fn transform_body<F>(self, transform: F) -> Self
Transform response body with a closure
Sourcepub fn with_headers<I, K, V>(self, headers: I) -> HttpResult<Self>
pub fn with_headers<I, K, V>(self, headers: I) -> HttpResult<Self>
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§impl From<ResponseBuilder> for ElifResponse
Convert ResponseBuilder to ElifResponse
impl From<ResponseBuilder> for ElifResponse
Convert ResponseBuilder to ElifResponse
Source§fn from(builder: ResponseBuilder) -> Self
fn from(builder: ResponseBuilder) -> Self
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