Skip to main content

Module web

Module web 

Source
Expand description

Web application framework.

use ntex::{web, SharedCfg};

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", SharedCfg::default())?
        .run()
        .await
}

§Documentation and community resources

Additional resources:

Useful API entry points include:

§Features

  • HTTP/1.x and HTTP/2
  • Streaming and pipelining
  • Keep-alive connections and slow-request handling
  • WebSocket clients and servers
  • Transparent zstd, gzip, and deflate content encoding
  • Configurable request routing
  • TLS through OpenSSL or rustls
  • Composable middleware

§Crate features

  • cookie enables HTTP cookie support.
  • compress enables gzip, deflate and zstd content compression and decompression.
  • openssl enables TLS support through OpenSSL.
  • rustls enables TLS support through rustls.
  • ws enables the ws module.

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::InternalError;
pub use self::error::WebError;
pub use self::error::WebResponseError;

Modules§

dev
Internal web framework types commonly needed by library authors.
error
Web error
guard
Route match guards.
middleware
Middlewares
stack
Middleware stack types used by applications, scopes, and resources.
test
Various helpers for ntex applications to use during testing.
types
Extractor types
ws
WebSockets protocol support

Structs§

App
The main builder for a web application.
AppServices
An application builder that already has routing configuration.
AppState
Wraps a value so it can be used as application state with DefaultError.
HttpRequest
An HTTP Request
HttpServer
An HTTP Server.
Resource
Groups routes and configuration for one or more URL patterns.
ResourceServices
A resource with routes or a configured fallback.
Route
Connects a handler to the requests it should handle.
Scope
Groups services under a shared path prefix.
ScopeServices
A scope with nested services or a configured fallback.
ServiceConfig
Service config is used for external configuration.
WebAppConfig
Application configuration
WebRequest
An service http request
WebResponse
An http service response.

Traits§

BodyEncoding
Helper trait that allows to set specific encoding for response.
FromRequest
Turns request data into a value that a handler can use.
Handler
Async fn handler.
HandlerSt
Async fn handler that receives the application and request state.
Responder
Turns a handler’s return value into an HTTP response.
State
Application state used by web services.
WebServiceFactory
Factory of web services that can be registered with an application or scope.

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.
query
Create route with QUERY 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.
server_with_config
Create new http server with application factory and configuration.
service
Create service adapter for a specific path.
to
Create an unguarded route with a handler.
to_with_state
Create a new route with a state-aware handler.

Attribute Macros§

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