pub fn on<S, B>(method: MethodFilter, svc: S) -> OnMethod<S, EmptyRouter<S::Error>, B>
where
    S: Service<Request<B>> + Clone,
{
    OnMethod {
        method,
        svc,
        fallback: EmptyRouter::method_not_allowed(),
        _request_body: PhantomData,
    }
}
/// Route requests with the given method to the service.
///
/// # Example
///
/// ```rust
/// use axum::{
///     http::Request,
///     handler::on,
///     service,
///     Router,
///     routing::MethodFilter,
/// };
/// use http::Response;
/// use std::convert::Infallible;
/// use hyper::Body;
///
/// let service = tower::service_fn(|request: Request<Body>| async {
///     Ok::<_, Infallible>(Response::new(Body::empty()))
/// });
///
/// // Requests to `POST /` will go to `service`.
/// let app = Router::new().route("/", service::on(MethodFilter::POST, service));
/// # async {
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
/// # };
/// ```
Route requests with the given method to the service.
Route requests with the given method to the service .
pub fn on<S, B>(method: MethodFilter, svc: S) -> OnMethod<S, EmptyRouter<S::Error>, B>
where
    S: Service<Request<B>> + Clone,
{
    OnMethod {
        method,
        svc,
        fallback: EmptyRouter::method_not_allowed(),
        _request_body: PhantomData,
    }
}
pub fn on < S , B > ( method : MethodFilter , svc : S ) -> OnMethod < S , EmptyRouter < S :: Error > , B > where S : Service < Request < B > > + Clone , { OnMethod { method , svc , fallback : EmptyRouter :: method_not_allowed ( ) , _request_body : PhantomData , } }
Route requests with the given method to the service.
Route requests with the given method to the service .
method
MethodFilter
svc
S
method
MethodFilter
svc
S
example
```rust
use axum::{
http::Request,
handler::on,
service,
Router,
routing::MethodFilter,
};
use http::Response;
use std::convert::Infallible;
use hyper::Body.

let service = tower::service_fn(|request: Request| async {
Ok::<_, Infallible>(Response::new(Body::empty()))
}).

Requests to `POST /` will go to `service`.
let app = Router::new().route("/", service::on(MethodFilter::POST, service)).
` ` ` rust use axum :: { http :: Request handler :: on service Router routing :: MethodFilter } ; use http :: Response ; use std :: convert :: Infallible ; use hyper :: Body . let service = tower :: service_fn ( |request : Request| async { Ok :: <_ Infallible > ( Response :: new ( Body :: empty () )) } ) . Requests to ` POST / ` will go to ` service ` . let app = Router :: new () . route ( " / " service :: on ( MethodFilter :: POST service )) .
async {
None
axum::server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
None
};
None