Skip to main content

server

Function server 

Source
pub fn server<F, I, S, B>(factory: F) -> HttpServer<F, I, S, B>
where F: AsyncFn() -> I + Send + Clone + 'static, I: IntoServiceFactory<S, Request, SharedCfg>, S: ServiceFactory<Request, SharedCfg> + 'static, S::Error: ResponseError, S::InitError: Debug, S::Response: Into<Response<B>>, B: MessageBody + 'static,
Expand description

Create new http server with application factory.

use ntex::web;

#[ntex::main]
async fn main() -> std::io::Result<()> {
    web::server(
        async || web::App::new()
            .service(web::resource("/").to(|| async { web::HttpResponse::Ok() })))
        .bind("127.0.0.1:59090")?
        .run()
        .await
}