Skip to content

Commit

Permalink
feat(volo-http): wrap DynService with Route
Browse files Browse the repository at this point in the history
With tie type `Route`, it can support `Service`, `Handler` and so on.

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
  • Loading branch information
wfly1998 committed Nov 24, 2023
1 parent ba05833 commit cd2be09
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 144 deletions.
16 changes: 11 additions & 5 deletions examples/src/http/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use volo_http::{
handler::HandlerService,
request::Json,
route::{Route, Router, ServiceLayerExt},
route::{MethodRouter, Router},
server::Server,
HttpContext,
};
Expand Down Expand Up @@ -73,16 +73,22 @@ async fn main() {
let app = Router::new()
.route(
"/",
Route::builder()
MethodRouter::builder()
.get(service_fn(hello))
.build()
.layer(TimeoutLayer::new(Some(std::time::Duration::from_secs(1)))),
)
.route("/:echo", Route::builder().get(service_fn(echo)).build())
.route("/user", Route::builder().post(service_fn(json)).build())
.route(
"/:echo",
MethodRouter::builder().get(service_fn(echo)).build(),
)
.route(
"/user",
MethodRouter::builder().post(service_fn(json)).build(),
)
.route(
"/test",
Route::builder()
MethodRouter::builder()
.get(HandlerService::new(test))
.post(HandlerService::new(test))
.build(),
Expand Down
Loading

0 comments on commit cd2be09

Please sign in to comment.