Skip to main content

service

Function service 

Source
pub fn service<T: IntoPattern>(path: T) -> WebServiceAdapter
Expand description

Create service adapter for a specific path.

use std::convert::Infallible;
use ntex::web::{self, guard, App, HttpResponse, WebError};

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)
);