pub struct WebServiceAdapter { /* private fields */ }Expand description
Create service adapter for a specific path.
use std::convert::Infallible;
use ntex::web::{self, guard, App, HttpResponse};
async fn my_service(req: web::WebRequest<()>) -> Result<web::WebResponse, Infallible> {
Ok(req.into_response(HttpResponse::Ok().build()))
}
let app = App::default().service(
web::service("/users/*")
.guard(guard::Header("content-type", "text/plain"))
.build(my_service)
);Implementations§
Source§impl WebServiceAdapter
impl WebServiceAdapter
Sourcepub fn new<T: IntoPattern>(path: T) -> Self
pub fn new<T: IntoPattern>(path: T) -> Self
Create new WebServiceAdapter instance.
Sourcepub fn guard<G: Guard + 'static>(self, guard: G) -> Self
pub fn guard<G: Guard + 'static>(self, guard: G) -> Self
Add a match guard to this web service.
The service is selected only when its path and all registered guards match. If a guard rejects the request, the router can try another matching service; otherwise the containing scope or application fallback is used.
use std::convert::Infallible;
use ntex::web::{self, guard, App, HttpResponse};
async fn index(
req: web::WebRequest<()>,
) -> Result<web::WebResponse, Infallible> {
Ok(req.into_response(HttpResponse::Ok().build()))
}
App::default().service(
web::service("/health")
.guard(guard::Get())
.guard(guard::Header("x-health-check", "true"))
.build(index)
);Sourcepub fn build<Sf, St, In, F>(self, service: F) -> impl WebServiceFactory<St, In>where
St: State,
In: 'static,
F: IntoServiceFactory<Sf, St, WebRequest<In>>,
Sf: ServiceFactory<St, WebRequest<In>, Res = WebResponse> + 'static,
Sf::Error: WebResponseError<St, St::Error>,
Sf::InitError: IntoFailure,
pub fn build<Sf, St, In, F>(self, service: F) -> impl WebServiceFactory<St, In>where
St: State,
In: 'static,
F: IntoServiceFactory<Sf, St, WebRequest<In>>,
Sf: ServiceFactory<St, WebRequest<In>, Res = WebResponse> + 'static,
Sf::Error: WebResponseError<St, St::Error>,
Sf::InitError: IntoFailure,
Set a service factory implementation and generate web service.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for WebServiceAdapter
impl !Send for WebServiceAdapter
impl !Sync for WebServiceAdapter
impl !UnwindSafe for WebServiceAdapter
impl Freeze for WebServiceAdapter
impl Unpin for WebServiceAdapter
impl UnsafeUnpin for WebServiceAdapter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more