Struct ElifResponse

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

Response builder for creating HTTP responses with fluent API

Implementations§

Source§

impl ElifResponse

Source

pub fn new() -> Self

Create new response with OK status

Source

pub fn with_status(status: StatusCode) -> Self

Create response with specific status code

Source

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

Set response status code

Source

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

Add header to response

Source

pub fn content_type(self, content_type: &str) -> HttpResult<Self>

Set Content-Type header

Source

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

Set response body as text

Source

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

Set response body as bytes

Source

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

Set response body as JSON

Source

pub fn json_value(self, value: Value) -> Self

Set response body as raw JSON value

Source

pub fn build(self) -> HttpResult<Response<Body>>

Build the response

Source§

impl ElifResponse

Convenience methods for common response types

Source

pub fn ok() -> Self

Create 200 OK response

Source

pub fn created() -> Self

Create 201 Created response

Source

pub fn no_content() -> Self

Create 204 No Content response

Source

pub fn bad_request() -> Self

Create 400 Bad Request response

Source

pub fn unauthorized() -> Self

Create 401 Unauthorized response

Source

pub fn forbidden() -> Self

Create 403 Forbidden response

Source

pub fn not_found() -> Self

Create 404 Not Found response

Source

pub fn unprocessable_entity() -> Self

Create 422 Unprocessable Entity response

Source

pub fn internal_server_error() -> Self

Create 500 Internal Server Error response

Source

pub fn json_ok<T: Serialize>(data: &T) -> HttpResult<Response<Body>>

Create JSON response with data

Source

pub fn json_error( status: StatusCode, message: &str, ) -> HttpResult<Response<Body>>

Create JSON error response

Source

pub fn validation_error<T: Serialize>(errors: &T) -> HttpResult<Response<Body>>

Create validation error response

Source§

impl ElifResponse

Redirect response builders

Source

pub fn redirect_permanent(location: &str) -> HttpResult<Self>

Create 301 Moved Permanently redirect

Source

pub fn redirect_temporary(location: &str) -> HttpResult<Self>

Create 302 Found (temporary) redirect

Source

pub fn redirect_see_other(location: &str) -> HttpResult<Self>

Create 303 See Other redirect

Source§

impl ElifResponse

File download response builders

Source

pub fn download(filename: &str, content: Bytes) -> HttpResult<Self>

Create file download response

Source

pub fn file_inline( filename: &str, content_type: &str, content: Bytes, ) -> HttpResult<Self>

Create inline file response (display in browser)

Trait Implementations§

Source§

impl Debug for ElifResponse

Source§

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

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

impl Default for ElifResponse

Source§

fn default() -> Self

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

impl IntoResponse for ElifResponse

Convert ElifResponse to Axum Response

Source§

fn into_response(self) -> Response

Create a response.

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
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,