Skip to content
ntex-rsPublic

About

ntex examples

Resources

Stars

97 stars

Watchers

7 watching

Forks

Repository files navigation

ntex examples

A curated list of examples for ntex, a framework for composable network services in Rust.

See also the ntex website and the API documentation.

Requirements

  • 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.

Running an example

All examples are members of a single Cargo workspace and use ntex 4. Change into an example directory and run it:

cd basics
cargo run

Some 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 test

Building extras/todo and extras/simple-auth-server requires the PostgreSQL client library (libpq).

Examples

Basics

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

Server

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

Extractors

Example Description
extractors/json JSON request and response handling
extractors/form URL-encoded form handling
extractors/multipart File uploads with multipart forms

Databases

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

Templates

Example Description
templates/askama Askama templates
templates/handlebars Handlebars templates
templates/tera Tera templates
templates/yarte Yarte templates

TLS

Example Description
tls/openssl HTTPS server with OpenSSL
tls/rustls HTTPS server with rustls

WebSockets

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

Testing

Example Description
tests/mockall Testing a state-aware service with mockall
tests/shimforge Testing a state-aware service with shimforge

Extras

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

License

This project is licensed under either of:

at your option.

About

ntex examples

Resources

Stars

97 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages