ResponseBuilder

Struct ResponseBuilder 

Source
pub struct ResponseBuilder { /* private fields */ }
Expand description

Response builder for fluent API construction

This struct provides a Laravel-inspired builder pattern for creating HTTP responses. All methods return Self for chaining, and the builder converts to ElifResponse automatically.

Implementations§

Source§

impl ResponseBuilder

Source

pub fn new() -> Self

Create new response builder

Source

pub fn ok(self) -> Self

Set status to 200 OK

Source

pub fn created(self) -> Self

Set status to 201 Created

Source

pub fn accepted(self) -> Self

Set status to 202 Accepted

Source

pub fn no_content(self) -> Self

Set status to 204 No Content

Source

pub fn bad_request(self) -> Self

Set status to 400 Bad Request

Source

pub fn unauthorized(self) -> Self

Set status to 401 Unauthorized

Source

pub fn forbidden(self) -> Self

Set status to 403 Forbidden

Source

pub fn not_found(self) -> Self

Set status to 404 Not Found

Source

pub fn unprocessable_entity(self) -> Self

Set status to 422 Unprocessable Entity

Source

pub fn internal_server_error(self) -> Self

Set status to 500 Internal Server Error

Source

pub fn status(self, status: ElifStatusCode) -> Self

Set custom status code

Source

pub fn json<T: Serialize>(self, data: T) -> Self

Set JSON body with automatic content-type

Source

pub fn text<S: Into<String>>(self, text: S) -> Self

Set text body

Source

pub fn html<S: Into<String>>(self, html: S) -> Self

Set HTML body

Source

pub fn bytes(self, bytes: Bytes) -> Self

Set binary body

Source

pub fn redirect<S: Into<String>>(self, location: S) -> Self

Create redirect response

Source

pub fn permanent(self) -> Self

Set redirect as permanent (301)

Source

pub fn temporary(self) -> Self

Set redirect as temporary (302) - default

Source

pub fn header<K, V>(self, key: K, value: V) -> Self
where K: Into<String>, V: Into<String>,

Add custom header

Source

pub fn location<S: Into<String>>(self, url: S) -> Self

Set location header

Source

pub fn cache_control<S: Into<String>>(self, value: S) -> Self

Set cache-control header

Source

pub fn content_type<S: Into<String>>(self, content_type: S) -> Self

Set content-type header

Source

pub fn cookie<S: Into<String>>(self, cookie_value: S) -> Self

Add a cookie header (supports multiple cookies)

Source

pub fn error<S: Into<String>>(self, message: S) -> Self

Create error response with message

Source

pub fn validation_error<T: Serialize>(self, errors: T) -> Self

Create validation error response

Source

pub fn not_found_with_message<S: Into<String>>(self, message: S) -> Self

Create not found error with custom message

Source

pub fn cors(self, origin: &str) -> Self

Add CORS headers

Source

pub fn cors_with_credentials(self, origin: &str) -> Self

Add CORS headers with credentials

Source

pub fn with_security_headers(self) -> Self

Add security headers

Source

pub fn send(self) -> HttpResult<ElifResponse>

Build and return the response wrapped in Ok()

This enables Laravel-style terminal chaining: response().json(data).send() Alternative to: Ok(response().json(data).into())

Source

pub fn finish(self) -> HttpResult<ElifResponse>

Build and return the response wrapped in Ok() - alias for send()

This enables Laravel-style terminal chaining: response().json(data).finish()

Source

pub fn build(self) -> ElifResponse

Build the final ElifResponse

Trait Implementations§

Source§

impl Debug for ResponseBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResponseBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<ResponseBuilder> for ElifResponse

Convert ResponseBuilder to ElifResponse

Source§

fn from(builder: ResponseBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,