pub struct Request { /* private fields */ }
Expand description

Represents an HTTP request.

Implementations

Creates a new Request with the given components parts and body.

Creates a request builder.

Returns a reference to the associated HTTP method.

Sets the HTTP method for this request.

Returns a reference to the associated URI.

Returns a mutable reference to the associated URI.

Returns a reference to the associated original URI.

Returns the associated version.

Sets the version for this request.

Returns the scheme of incoming request.

Returns a reference to the associated header map.

Returns a mutable reference to the associated header map.

Returns the string value of the specified header.

NOTE: Returns None if the header value is not a valid UTF8 string.

Returns the raw path parameter with the specified name.

Deserialize path parameters.

See also Path

Example
use poem::{
    handler,
    http::{StatusCode, Uri},
    test::TestClient,
    Endpoint, Request, Result, Route,
};

#[handler]
fn index(req: &Request) -> Result<String> {
    let (a, b) = req.path_params::<(i32, String)>()?;
    Ok(format!("{}:{}", a, b))
}

let app = Route::new().at("/:a/:b", index);
let cli = TestClient::new(app);

let resp = cli.get("/100/abc").send().await;
resp.assert_status_is_ok();
resp.assert_text("100:abc").await;

Deserialize query parameters.

See also Query

Example
use poem::{
    handler,
    http::{StatusCode, Uri},
    test::TestClient,
    Endpoint, Request, Result, Route,
};
use serde::Deserialize;

#[derive(Deserialize)]
struct Params {
    a: i32,
    b: String,
}

#[handler]
fn index(req: &Request) -> Result<String> {
    let params = req.params::<Params>()?;
    Ok(format!("{}:{}", params.a, params.b))
}

let app = Route::new().at("/", index);
let cli = TestClient::new(app);

let resp = cli
    .get("/")
    .query("a", &100)
    .query("b", &"abc")
    .send()
    .await;
resp.assert_status_is_ok();
resp.assert_text("100:abc").await;

Returns the content type of this request.

Returns a reference to the associated extensions.

Returns a mutable reference to the associated extensions.

Get a reference from extensions, similar to self.extensions().get().

Inserts a value to extensions, similar to self.extensions().insert(data).

Returns a reference to the remote address.

Returns a reference to the local address.

Available on crate feature cookie only.

Returns a reference to the CookieJar

Sets the body for this request.

Take the body from this request and sets the body to empty.

Consume this request and return its inner body.

Returns the parameters used by the extractor.

Consumes the request returning the head and body parts.

Upgrade the connection and return a stream.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Extract from request head and body.
Extract from request head. 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.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self
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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more