logo

Struct poem::RouteMethod[][src]

pub struct RouteMethod { /* fields omitted */ }
Expand description

Routing object for HTTP methods

Errors

Example

use poem::{
    handler,
    http::{Method, StatusCode},
    Endpoint, Request, RouteMethod,
};

#[handler]
fn handle_get() -> &'static str {
    "get"
}

#[handler]
fn handle_post() -> &'static str {
    "post"
}

let route_method = RouteMethod::new().get(handle_get).post(handle_post);

let resp = route_method
    .get_response(Request::builder().method(Method::GET).finish())
    .await;
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.into_body().into_string().await.unwrap(), "get");

let resp = route_method
    .get_response(Request::builder().method(Method::POST).finish())
    .await;
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.into_body().into_string().await.unwrap(), "post");

let resp = route_method
    .get_response(Request::builder().method(Method::PUT).finish())
    .await;
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);

Implementations

Create a RouteMethod object.

Sets the endpoint for specified method.

Sets the endpoint for GET.

Sets the endpoint for POST.

Sets the endpoint for PUT.

Sets the endpoint for DELETE.

Sets the endpoint for HEAD.

Sets the endpoint for OPTIONS.

Sets the endpoint for CONNECT.

Sets the endpoint for PATCH.

Sets the endpoint for TRACE.

Trait Implementations

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

Represents the response of the endpoint.

Get the response to the request.

Get the response to the request and return a Response. 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

Performs the conversion.

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

Performs the conversion.

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