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:
Appconfigures routes, application state, and middleware.HttpServercreates and configures HTTP server instances.HttpRequestprovides request metadata and application state.HttpResponseandWebResponserepresent HTTP responses.resource()androute()configure resource and route matching.
§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
cookieenables HTTP cookie support.compressenables gzip, deflate and zstd content compression and decompression.opensslenables TLS support through OpenSSL.rustlsenables TLS support through rustls.wsenables thewsmodule.
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
WebSocketsprotocol 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. - Http
Request - An HTTP Request
- Http
Server - An HTTP Server.
- Resource
- Groups routes and configuration for one or more URL patterns.
- Resource
Services - 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.
- Scope
Services - A scope with nested services or a configured fallback.
- Service
Config - Service config is used for external configuration.
- WebApp
Config - Application configuration
- WebRequest
- An service http request
- WebResponse
- An http service response.
Traits§
- Body
Encoding - Helper trait that allows to set specific encoding for response.
- From
Request - Turns request data into a value that a handler can use.
- Handler
- Async fn handler.
- Handler
St - 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.
- WebService
Factory - 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
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. - query
- Create route with
QUERYmethod 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
CONNECTmethod guard. - delete
- Creates a route handler with a
DELETEmethod guard. - get
- Creates a route handler with a
GETmethod guard. - head
- Creates a route handler with a
HEADmethod guard. - options
- Creates a route handler with a
OPTIONSmethod guard. - patch
- Creates a route handler with a
PATCHmethod guard. - post
- Creates a route handler with a
POSTmethod guard. - put
- Creates a route handler with a
PUTmethod guard. - query
- Creates a route handler with a
QUERYmethod guard. - trace
- Creates a route handler with a
TRACEmethod guard.