hyperium / hyperium/hyper

Provide example on how to use hyper 1.0.0 with tower layers

Open
#3,154 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs E-easy
Dominant language
Rust
Stars
16.3k
Forks
1.8k
Avg merge
1d 22h
Merged PRs (30d)
14

Description

Version
1.0.0-rc.3

Platform
Not relevant

Description
Can some of the examples for hyper 1.0.0 show how to make use of tower layers with hyper 1.0.0-rc.3?

All of the examples I can find online where people are using older versions of hyper with tower rely on the higher level Server API.

How do you use the lower level hyper 1.0.0 API like in https://hyper.rs/guides/1/server/hello-world/

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    // We create a TcpListener and bind it to 127.0.0.1:3000
    let listener = TcpListener::bind(addr).await?;

    // We start a loop to continuously accept incoming connections
    loop {
        let (stream, _) = listener.accept().await?;

        // Spawn a tokio task to serve multiple connections concurrently
        tokio::task::spawn(async move {
            // Finally, we bind the incoming connection to our `hello` service
            if let Err(err) = http1::Builder::new()
                // `service_fn` converts our function in a `Service`
                .serve_connection(stream, service_fn(hello))
                .await
            {
                println!("Error serving connection: {:?}", err);
            }
        });
    }
}

with tower layers?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the hyper.rs 1.0 server/hello-world guide and the lower-level http1::Builder example included in the issue. Document a working example that applies Tower layers with Hyper 1.0's lower-level API, and verify that the example is clear and runnable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.