You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _stable/server/middleware.md
+99-15Lines changed: 99 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,35 +3,39 @@ title: Getting Started with a Server Middleware
3
3
layout: guide
4
4
---
5
5
6
-
As [Upgrade](https://hyper.rs/guides/1/upgrading/) mentioned, hyper v1 is not depended on tower for the Service trait. When we want to add tower-like middleware, there are 2 kind of approach to make it.
6
+
As [Upgrade](upgrading) mentioned, hyper v1 is not depended on tower for the Service trait. When we want to add tower-like middleware, there are 2 kind of approach to make it.
7
7
8
-
Let's create a Logger middleware in [hello-world server](https://hyper.rs/guides/1/server/hello-world/) for instance:
8
+
Let's create a Logger middleware in [hello-world server](hello-world) for instance:
9
9
10
10
Add tower dependency first
11
11
12
-
```rust
12
+
```toml
13
13
[dependencies]
14
14
hyper = { version = "1", features = ["full"] }
15
15
tokio = { version = "1", features = ["full"] }
16
16
http-body-util = "0.1"
17
17
hyper-util = { version = "0.1", features = ["full"] }
18
-
tower={ version="0.4.13" } // here
18
+
tower = "0.4"# here
19
19
```
20
20
21
21
## Option 1: Use hyper Service trait
22
22
23
23
Implement hyper Logger middleware
24
24
25
25
```rust
26
-
usehyper::{body::Incoming, service::Service}; // using hyper Service trait
[hyper_util::service::TowerToHyperService](https://docs.rs/hyper-util/latest/hyper_util/service/struct.TowerToHyperService.html) trait is an adapter to convert tower Service to hyper Service.
125
+
[hyper_util::service::TowerToHyperService](adapter-trait) trait is an adapter to convert tower Service to hyper Service.
0 commit comments