Struct poem::RouteMethod
source · [−]pub struct RouteMethod { /* private fields */ }
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
sourceimpl RouteMethod
impl RouteMethod
sourcepub 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 the specified method
.
sourcepub fn get<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn get<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for GET
.
sourcepub fn post<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn post<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for POST
.
sourcepub fn put<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn put<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for PUT
.
sourcepub fn delete<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn delete<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for DELETE
.
sourcepub fn head<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn head<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for HEAD
.
sourcepub fn options<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn options<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for OPTIONS
.
sourcepub fn connect<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn connect<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for CONNECT
.
sourcepub fn patch<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn patch<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for PATCH
.
sourcepub fn trace<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
pub fn trace<E>(self, ep: E) -> Self where
E: IntoEndpoint,
E::Endpoint: 'static,
Sets the endpoint for TRACE
.
Trait Implementations
sourceimpl Default for RouteMethod
impl Default for RouteMethod
sourcefn default() -> RouteMethod
fn default() -> RouteMethod
Returns the “default value” for a type. Read more
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more