Skip to content

examples: add ServiceBuilder middleware composition example#854

Open
Sim-hu wants to merge 1 commit intotower-rs:masterfrom
Sim-hu:service-builder-example
Open

examples: add ServiceBuilder middleware composition example#854
Sim-hu wants to merge 1 commit intotower-rs:masterfrom
Sim-hu:service-builder-example

Conversation

@Sim-hu
Copy link
Copy Markdown

@Sim-hu Sim-hu commented Mar 8, 2026

Summary

  • Adds a new example (service-builder.rs) showing how to compose middleware with ServiceBuilder
  • Chains ConcurrencyLimit, RateLimit, and Timeout around a simple async service
  • Demonstrates the core tower pattern that most users need when getting started

Motivation

Tower currently has only one example (tower-balance), which is fairly advanced. ServiceBuilder is the primary entry point for most users, but there's no simple example showing how to use it. This fills that gap with a minimal, self-contained example.

Checklist

  • cargo build --example service-builder --features full
  • cargo run --example service-builder --features full
  • cargo clippy --example service-builder --features full
  • cargo fmt --check

Add a simple example showing how to compose multiple middleware layers
using `ServiceBuilder`. The example chains `ConcurrencyLimit`,
`RateLimit`, and `Timeout` around a basic async service, demonstrating
the core tower pattern of layered middleware.

Tower currently has very few examples, and `ServiceBuilder` is the
primary entry point for most users. This fills that gap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant