pub struct ApiResponse {
    pub body: String,
    pub headers: HeaderMap,
    pub status: StatusCode,
}
Expand description

The integration-agnostic representation of the response Perseus will give to HTTP requests.

Fields§

§body: String

The actual response body.

§headers: HeaderMap

The additional headers for the response. These will not include things like caching directives and the like, as they are expected to be handled by integrations.

§status: StatusCode

The HTTP status code of the response.

Implementations§

source§

impl ApiResponse

source

pub fn ok(body: &str) -> Self

Creates a 200 OK response with the given body and MIME type.

source

pub fn not_found(msg: &str) -> Self

Creates a 404 Not Found response.

source

pub fn err(status: StatusCode, body: &str) -> Self

Creates some other error response.

source

pub fn add_header(&mut self, k: HeaderName, v: HeaderValue)

Adds the given header to this response.

source

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

Sets the Content-Type HTTP header to the given MIME type, which tells the browser what file type it has actually been given. For HTML, this is especially important!

As this is typically called last, and only once, it consumes self for ergonomics. If this is not desired, the .add_header() method can be manually invoked.

Panics

This will panic if the given MIME type contains invalid ASCII characters.

Trait Implementations§

source§

impl Debug for ApiResponse

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.