Update readme.

This commit is contained in:
Alec Thilenius 2023-12-28 11:52:42 -05:00
parent 48752280e4
commit 80d49d8ca5

View file

@ -109,10 +109,9 @@ fn main() {
With the boring stuff out of the way, let's implement our service using Axum!
```rust
use std::net::SocketAddr;
use async_stream::stream;
use axum::{extract::Host, Router};
use axum_connect::prelude::*;
use axum_connect::{futures::Stream, prelude::*};
use proto::hello::*;
mod proto {
@ -123,19 +122,18 @@ mod proto {
#[tokio::main]
async fn main() {
// Build our application with a route. Note the `rpc` method which was added
// by `axum-connect`. It expect a service method handler, wrapped in it's
// respective type. The handler (below) is just a normal Rust function. Just
// like Axum, it also supports extractors!
let app = Router::new().rpc(HelloWorldService::say_hello(say_hello_success));
// Build our application with a route. Note the `rpc` method which was added by `axum-connect`.
// It expect a service method handler, wrapped in it's respective type. The handler (below) is
// just a normal Rust function. Just like Axum, it also supports extractors!
let app = Router::new()
.rpc(HelloWorldService::say_hello(say_hello_success))
.rpc(HelloWorldService::say_hello_stream(say_hello_stream));
// Axum boilerplate to start the server.
let addr = SocketAddr::from(([127, 0, 0, 1], 3030));
println!("listening on http://{}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
let listener = tokio::net::TcpListener::bind("127.0.0.1:3030")
.await
.unwrap();
println!("listening on http://{:?}", listener.local_addr());
axum::serve(listener, app).await.unwrap();
}
async fn say_hello_success(