Struct direkuta::Response

source ·
pub struct Response { /* private fields */ }
Expand description

A wrapper around Hyper Response.

Implementations§

Constructs a new Response.

Examples
let res = Response::new();

Return Response HTTP version.

Return Response HTTP headers.

Return Response HTTP headers.

Examples
let mut res = Response::new();
res.headers_mut().insert(
    header::CONTENT_TYPE,
    HeaderValue::from_static("text/plain")
);

Set Response’s HTTP headers.

Builder set Response’s HTTP headers.

Return Response HTTP status code.

Get mutable reference to Response’s status code.

Set Response’s HTTP status code.

Examples
let mut res = Response::new();
res.set_status(404);

Set Response’s HTTP status code.

Examples
let res = Response::new()
    .with_status(404);

Return Response HTTP body.

Get mutable reference to Response’s body.

Set Response’s HTTP body.

Examples
let mut res = Response::new();
res.set_body("Hello World!");

Set Response’s HTTP body.

Examples
let res = Response::new()
    .with_body("Hello World!");

Set Response’s redirect location as status code.

Examples
let mut res = Response::new();
res.redirect("/example/moved");

Set Response’s redirect location as status code.

Examples
let res = Response::new()
    .with_redirect("/example/moved");

Wrapper around Response.set_body for the HTML context type.

Wrapper around Response.set_body for the HTML context type.

Wrapper around Response.set_body for the CSS context type.

Wrapper around Response.set_body for the CSS context type.

Wrapper around Response.set_body for the JS context type.

Wrapper around Response.set_body for the JS context type.

Wrapper around Response.set_body for the JSON context type.

Examples

use direkuta::prelude::*;

#[derive(Serialize)]
struct Example {
    hello: String,
}
let mut res = Response::new();
res.json(|j| {
    j.body(Example {
        hello: String::from("world"),
    });
});

Builder function for Json responses.

Examples

use direkuta::prelude::*;

#[derive(Serialize)]
struct Example {
    hello: String,
}
let res = Response::new()
    .with_json(|j| {
        j.body(Example {
            hello: String::from("world"),
        });
    });

Builder function for Json responses.

Examples

use direkuta::prelude::*;

#[derive(Serialize)]
struct Example {
    hello: String,
}
let res = Response::new();
res.json_body(Example {
    hello: String::from("world"),
});

Transform the Response into a Hyper Response.

Wrapper around ‘into_hyper’ to change it into a future response.

Trait Implementations§

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

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.