Module ntex::web

source ·
Expand description

Web framework for Rust.

use ntex::web;

async fn index(info: web::types::Path<(String, u32)>) -> String {
    format!("Hello {}! id:{}", info.0, info.1)
}

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

§Documentation & community resources

Besides the API documentation (which you are currently looking at!), several other resources are available:

To get started navigating the API documentation you may want to consider looking at the following pages:

  • App: This struct represents an ntex web application and is used to configure routes and other common settings.

  • HttpServer: This struct represents an HTTP server instance and is used to instantiate and configure servers.

  • HttpRequest and HttpResponse: These structs represent HTTP requests and responses and expose various methods for inspecting, creating and otherwise utilizing them.

§Features

  • Supported HTTP/1.x and HTTP/2.0 protocols
  • Streaming and pipelining
  • Keep-alive and slow requests handling
  • WebSockets server/client
  • Transparent content compression/decompression (br, gzip, deflate)
  • Configurable request routing
  • SSL support with OpenSSL or rustls
  • Middlewares
  • Supported Rust version: 1.41 or later

§Package feature

  • cookie - enables http cookie support
  • compress - enables content encoding compression support
  • openssl - enables ssl support via openssl crate
  • rustls - enables ssl support via rustls crate

Re-exports§

Modules§

  • The ntex::web prelude for library developers
  • Web error
  • Route match guards.
  • Middlewares
  • Various helpers for ntex applications to use during testing.
  • Extractor types
  • WebSockets protocol support

Structs§

  • Application builder - structure that follows the builder pattern for building application instances.
  • An HTTP Request
  • An HTTP Server.
  • Resource is an entry in resources table which corresponds to requested URL.
  • Resource route definition
  • Resources scope.
  • Service config is used for external configuration. Part of application configuration could be offloaded to set of external methods. This could help with modularization of big application configuration.
  • An service http request
  • An service http response

Traits§

Functions§

  • Execute blocking function on a thread pool, returns future that resolves to result of the function execution.
  • Create route with DELETE method guard.
  • Create route with GET method guard.
  • Create route with HEAD method guard.
  • Create route and add method guard.
  • Create route with PATCH method guard.
  • Create route with POST method guard.
  • Create route with PUT method guard.
  • Create resource for a specific path.
  • Create route without configuration.
  • Configure scope for common root path.
  • Create new http server with application factory.
  • Create service adapter for a specific path.
  • Create a new route and add handler.

Attribute Macros§

  • Creates route handler with CONNECT method guard.
  • Creates route handler with DELETE method guard.
  • Creates route handler with GET method guard.
  • Creates route handler with HEAD method guard.
  • Creates route handler with OPTIONS method guard.
  • Creates route handler with PATCH method guard.
  • Creates route handler with POST method guard.
  • Creates route handler with PUT method guard.
  • Creates route handler with TRACE method guard.