Module ntex::web [−][src]
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 supportcompress
- enables content encoding compression supportopenssl
- enables ssl support viaopenssl
craterustls
- enables ssl support viarustls
crate
Re-exports
pub use self::error::ErrorContainer; |
pub use self::error::ErrorRenderer; |
pub use self::error::WebResponseError; |
Modules
dev | The |
error | Web error |
guard | Route match guards. |
middleware | Middlewares |
test | Various helpers for ntex applications to use during testing. |
types | Extractor types |
ws |
Structs
App | Application builder - structure that follows the builder pattern for building application instances. |
DefaultError | Default error type |
Error | Generic error container for errors that supports |
HttpRequest | An HTTP Request |
HttpResponse | An HTTP Response |
HttpResponseBuilder | An HTTP response builder |
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. Part of application configuration could be offloaded to set of external methods. This could help with modularization of big application configuration. |
Enums
Either | The enum |
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. |
Functions
block | Execute blocking function on a thread pool, returns future that resolves to result of the function execution. |
delete | Create route with |
get | Create route with |
head | Create route with |
method | Create route and add method guard. |
patch | Create route with |
post | Create route with |
put | Create route with |
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 |
delete | Creates route handler with |
get | Creates route handler with |
head | Creates route handler with |
options | Creates route handler with |
patch | Creates route handler with |
post | Creates route handler with |
put | Creates route handler with |
trace | Creates route handler with |