Skip to content

Commit 62a6f66

Browse files
authored
HTTP/2 server example (#139)
* add http2 server guide * fix impl service link * fixes after proofreading * deleted http2 example md and added example to hello-world.md * Implemented suggestions
1 parent 1126c63 commit 62a6f66

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

_stable/server/hello-world.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ layout: guide
55

66
Let's start by making a "Hello, World!" server, and expand from there.
77

8-
First we need to declare our dependencies, let's add the following to our `Cargo.toml`:
8+
First, we need to declare our dependencies, let's add the following to our `Cargo.toml`:
99

1010
```toml
1111
[dependencies]
@@ -43,7 +43,7 @@ incoming requests. It represents an async function that takes a
4343
future is complete, it will resolve to a [`Response`][response] or an error.
4444

4545
Hyper provides a utility for creating a `Service` from a function that should
46-
serve most usecases: [`service_fn`][service_fn]. We will use this to create
46+
serve most use cases: [`service_fn`][service_fn]. We will use this to create
4747
a service from our `hello` function below when we're ready to start our
4848
server.
4949

@@ -67,7 +67,7 @@ set automatically.
6767

6868
## Starting the Server
6969

70-
Lastly, we need to hook up our `hello` service into a running hyper server.
70+
Lastly, we need to hook up our `hello` service into a running Hyper server.
7171

7272
We'll dive in to the specifics of some of these things in another guide.
7373

@@ -129,10 +129,21 @@ To see all the snippets put together, check out the [full example][example]!
129129
Also, if `service_fn` doesn't meet your requirements and you'd like to implement
130130
`Service` yourself, see this [example][impl service].
131131

132+
## HTTP/2
133+
134+
This example uses the `http1` module to create a server that speaks HTTP/1.
135+
In case you want to use HTTP/2, you can use the `http2` module with a few changes to the
136+
http1 server. The http2 builder requires an executor to run. Executor should implement the `hyper::rt::Executor` trait.
137+
138+
To implement the Executor, check out the runtime [example][runtime].
139+
To see the full example with HTTP/2, check out the [full example][example_http2]!
140+
132141
[service]: {{ site.hyper_docs_url }}/hyper/service/trait.Service.html
133142
[service_fn]: {{ site.hyper_docs_url }}/hyper/service/fn.service_fn.html
134143
[request]: {{ site.hyper_docs_url }}/hyper/struct.Request.html
135144
[response]: {{ site.hyper_docs_url }}/hyper/struct.Response.html
136145
[parts]: {{ site.http_docs_url }}/http/response/struct.Parts.html
137146
[example]: {{ site.examples_url }}/hello.rs
147+
[example_http2]: {{ site.examples_url }}/hello-http2.rs
148+
[runtime]: ../init/runtime.md
138149
[impl service]: {{ site.examples_url }}/service_struct_impl.rs

0 commit comments

Comments
 (0)