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. -
HttpRequestandHttpResponse: 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
WebSocketsserver/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 viaopensslcraterustls- enables ssl support viarustlscrate
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::webprelude 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
WebSocketsprotocol support
Structs§
- App
- Application builder - structure that follows the builder pattern for building application instances.
- Http
Request - An HTTP Request
- Http
Server - An HTTP Server.
- Resource
- Resource is an entry in resources table which corresponds to requested URL.
- Route
- Resource route definition
- Scope
- Resources scope.
- Service
Config - Service config is used for external configuration.
- WebApp
Config - Application configuration
- WebRequest
- An service http request
- WebResponse
- An service http response
Traits§
- Body
Encoding - Helper trait that allows to set specific encoding for response.
- From
Request - 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.
- WebService
Factory
Functions§
- block
- Execute blocking function on a thread pool, returns future that resolves to result of the function execution.
- delete
- Create route with
DELETEmethod guard. - get
- Create route with
GETmethod guard. - head
- Create route with
HEADmethod guard. - method
- Create route and add method guard.
- patch
- Create route with
PATCHmethod guard. - post
- Create route with
POSTmethod guard. - put
- Create route with
PUTmethod 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
CONNECTmethod guard. - delete
- Creates route handler with
DELETEmethod guard. - get
- Creates route handler with
GETmethod guard. - head
- Creates route handler with
HEADmethod guard. - options
- Creates route handler with
OPTIONSmethod guard. - patch
- Creates route handler with
PATCHmethod guard. - post
- Creates route handler with
POSTmethod guard. - put
- Creates route handler with
PUTmethod guard. - trace
- Creates route handler with
TRACEmethod guard.