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
.call(Request::builder().method(Method::GET).finish())
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.into_body().into_string().await.unwrap(), "get");
let resp = route_method
.call(Request::builder().method(Method::POST).finish())
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.into_body().into_string().await.unwrap(), "post");
Implementations
pub fn method<E>(self, method: Method, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn method<E>(self, method: Method, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
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
Get the response to the request.
Auto Trait Implementations
impl !RefUnwindSafe for RouteMethod
impl Send for RouteMethod
impl Sync for RouteMethod
impl Unpin for RouteMethod
impl !UnwindSafe for RouteMethod
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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