mirror of
https://github.com/AThilenius/axum-connect.git
synced 2025-01-05 01:39:14 +00:00
Update readme.
This commit is contained in:
parent
48752280e4
commit
80d49d8ca5
1 changed files with 11 additions and 13 deletions
24
README.md
24
README.md
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue