Skip to content

Examples

The repository’s examples/ directory holds small, complete apps. Each one runs with cargo run --example <name> from a clone and has a test that cargo test runs, so they keep compiling and working as the crate changes.

Terminal window
git clone https://github.com/bohdaq/rust-web-server && cd rust-web-server
cargo run --example hello
curl localhost:7878/hello/world # Hello, world!

Without a certificate they serve plain HTTP/1.1 on port 7878; a rws.config.toml in the working directory, environment variables and command-line flags apply as they do to rws (see Configuration).

Example Shows Run Read more
hello Two routes and a path parameter cargo run --example hello Routing
rest_api JSON CRUD over shared state, typed errors (400, 404, 422) cargo run --example rest_api --features serde JSON, Error handling
static_site The working directory as a site, behind request-id and rate-limit middleware cargo run --example static_site Static files, Middleware
reverse_proxy /api/* forwarded to a backend, the rest served locally cargo run --example reverse_proxy Reverse proxy
sse_ticker Server-sent events written as they are produced cargo run --example sse_ticker Server-sent events
upload Large uploads streamed to disk, not buffered cargo run --example upload Forms and uploads
mcp_inventory One domain served as a REST API and as MCP tools for agents cargo run --example mcp_inventory --features "macros serde sso" Agent tools
mcp_gateway One authenticated MCP endpoint in front of several MCP servers cargo run --example mcp_gateway MCP gateway
mcp_conformance The server the official MCP conformance suite tests cargo run --example mcp_conformance MCP overview

The comment at the top of each file has the curl commands to try it.

Each example builds its app in a function (app()) that main serves and its test drives through TestClient — no socket, no port. Copy that split into your own app:

Terminal window
cargo test --example rest_api --features serde

AGENTS.md at the repository root tells a coding agent how to build an app on the crate: which entry point to start from, the handler signature, the conventions that aren’t obvious from the types, and where in these docs each topic lives. The whole documentation is also available as one file, llms-full.txt.