A curated list of examples for ntex, a framework for composable network services in Rust.
See also the ntex website and the API documentation.
- Rust 1.97 or later
- Some examples need extra services or libraries (PostgreSQL and
libpq, MySQL, SQLite, OpenSSL); see the README in each example directory.
All examples are members of a single Cargo workspace and use ntex 4. Change into an example directory and run it:
cd basics
cargo runSome examples read static files or templates relative to their own
directory, so run them from there. Most examples listen on
http://127.0.0.1:8080/; check the example's README or main.rs for the
address. Examples with multiple binaries (for example the websocket server and
client) are started with cargo run --bin <name>.
To build or test the whole workspace:
cargo build
cargo testBuilding extras/todo and extras/simple-auth-server requires the
PostgreSQL client library (libpq).
| Example | Description |
|---|---|
| basics | Routing, path parameters, sessions, static files and error pages |
| error | Custom error types and error propagation |
| middleware | Writing and using custom middleware |
| state/process | Process-wide and per-worker application state |
| state/state-accumulation | Per-connection state, including TLS connection info |
| state/web-state | web::App state in middleware, filters, handlers and errors |
| Example | Description |
|---|---|
| server/tokio | The basics example running on the Tokio runtime |
| server/run-in-thread | Running the server in a separate thread and stopping it |
| server/shutdown | Shutting down the server remotely or with a signal |
| server/unix-socket | Serving HTTP over a Unix domain socket |
| server/docker | Building and running an ntex application in Docker |
| Example | Description |
|---|---|
| extractors/json | JSON request and response handling |
| extractors/form | URL-encoded form handling |
| extractors/multipart | File uploads with multipart forms |
| Example | Description |
|---|---|
| db/async-db | Running blocking SQLite queries asynchronously |
| db/async-pg | PostgreSQL with tokio-postgres and deadpool |
| db/r2d2 | SQLite with an r2d2 connection pool |
| db/diesel | Diesel with SQLite |
| db/juniper | GraphQL with Juniper |
| db/graphql | GraphQL with Juniper and MySQL |
| Example | Description |
|---|---|
| templates/askama | Askama templates |
| templates/handlebars | Handlebars templates |
| templates/tera | Tera templates |
| templates/yarte | Yarte templates |
| Example | Description |
|---|---|
| tls/openssl | HTTPS server with OpenSSL |
| tls/rustls | HTTPS server with rustls |
| Example | Description |
|---|---|
| websockets/basic | WebSocket echo server and client |
| websockets/lowlevel | WebSocket server and client using the low-level API |
| websockets/chat | WebSocket chat server |
| websockets/tcp-chat | Chat server with WebSocket and TCP clients |
| Example | Description |
|---|---|
| tests/mockall | Testing a state-aware service with mockall |
| tests/shimforge | Testing a state-aware service with shimforge |
| Example | Description |
|---|---|
| extras/async-ex1 | Chaining async steps, including outgoing HTTP client requests |
| extras/async-ex2 | Nested resource registration through application configuration |
| extras/http-client | HTTPS requests with the ntex HTTP client |
| extras/http-proxy | HTTP proxy forwarding requests to another server |
| extras/json-error | Rendering errors as JSON responses |
| extras/jsonrpc | JSON-RPC over HTTP server |
| extras/server-sent-events | Server-sent events (EventSource) |
| extras/cookie-session | Cookie-based sessions |
| extras/cookie-auth | Cookie-based identity and authentication |
| extras/simple-auth-server | Registration and login with email invitations, Diesel and PostgreSQL |
| extras/todo | Todo application with Diesel, PostgreSQL and Tera templates |
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.