Struct ntex::web::dev::WebServiceAdapter
source · pub struct WebServiceAdapter { /* private fields */ }
Expand description
Create service adapter for a specific path.
use ntex::web::{self, guard, App, HttpResponse, Error, DefaultError};
async fn my_service(req: web::WebRequest<DefaultError>) -> Result<web::WebResponse, Error> {
Ok(req.into_response(HttpResponse::Ok().finish()))
}
let app = App::new().service(
web::service("/users/*")
.guard(guard::Header("content-type", "text/plain"))
.finish(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 match guard to a web service.
use ntex::web::{self, guard, App, DefaultError, Error, HttpResponse};
async fn index(req: web::WebRequest<DefaultError>) -> Result<web::WebResponse, Error> {
Ok(req.into_response(HttpResponse::Ok().finish()))
}
fn main() {
let app = App::new()
.service(
web::service("/app")
.guard(guard::Header("content-type", "text/plain"))
.finish(index)
);
}
sourcepub fn finish<T, F, Err>(self, service: F) -> impl WebServiceFactory<Err>where
F: IntoServiceFactory<T, WebRequest<Err>>,
T: ServiceFactory<WebRequest<Err>, Response = WebResponse, Error = Err::Container> + 'static,
Err: ErrorRenderer,
pub fn finish<T, F, Err>(self, service: F) -> impl WebServiceFactory<Err>where
F: IntoServiceFactory<T, WebRequest<Err>>,
T: ServiceFactory<WebRequest<Err>, Response = WebResponse, Error = Err::Container> + 'static,
Err: ErrorRenderer,
Set a service factory implementation and generate web service.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WebServiceAdapter
impl !RefUnwindSafe for WebServiceAdapter
impl !Send for WebServiceAdapter
impl !Sync for WebServiceAdapter
impl Unpin for WebServiceAdapter
impl !UnwindSafe 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