Skip to main content

Module web

Module 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(async || 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§

pub use crate::http::Response as HttpResponse;
pub use crate::http::ResponseBuilder as HttpResponseBuilder;
pub use self::error::DefaultError;
pub use self::error::Error;
pub use self::error::ErrorContainer;
pub use self::error::ErrorRenderer;
pub use self::error::WebResponseError;

Modules§

dev
The ntex::web prelude for library developers
error
Web error
guard
Route match guards.
middleware
Middlewares
stack
test
Various helpers for ntex applications to use during testing.
types
Extractor types
ws
WebSockets protocol support

Structs§

App
Application builder - structure that follows the builder pattern for building application instances.
HttpRequest
An HTTP Request
HttpServer
An HTTP Server.
Resource
Resource is an entry in resources table which corresponds to requested URL.
Route
Resource route definition
Scope
Resources scope.
ServiceConfig
Service config is used for external configuration.
WebAppConfig
Application configuration
WebRequest
An service http request
WebResponse
An service http response

Traits§

BodyEncoding
Helper trait that allows to set specific encoding for response.
FromRequest
Trait implemented by types that can be extracted from request.
Handler
Async fn handler
Responder
Trait implemented by types that can be converted to a http response.
WebServiceFactory

Functions§

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

Attribute Macros§

connect
Creates route handler with CONNECT method guard.
delete
Creates route handler with DELETE method guard.
get
Creates route handler with GET method guard.
head
Creates route handler with HEAD method guard.
options
Creates route handler with OPTIONS method guard.
patch
Creates route handler with PATCH method guard.
post
Creates route handler with POST method guard.
put
Creates route handler with PUT method guard.
trace
Creates route handler with TRACE method guard.