]>
Commit | Line | Data |
---|---|---|
13cf67c4 XL |
1 | # Final Project: Building a Multithreaded Web Server |
2 | ||
3 | It’s been a long journey, but we’ve reached the end of the book. In this | |
4 | chapter, we’ll build one more project together to demonstrate some of the | |
5 | concepts we covered in the final chapters, as well as recap some earlier | |
6 | lessons. | |
7 | ||
8 | For our final project, we’ll make a web server that says “hello” and looks like | |
9 | Figure 20-1 in a web browser. | |
10 | ||
11 | ![hello from rust](img/trpl20-01.png) | |
12 | ||
13 | <span class="caption">Figure 20-1: Our final shared project</span> | |
14 | ||
15 | Here is the plan to build the web server: | |
16 | ||
17 | 1. Learn a bit about TCP and HTTP. | |
18 | 2. Listen for TCP connections on a socket. | |
19 | 3. Parse a small number of HTTP requests. | |
20 | 4. Create a proper HTTP response. | |
21 | 5. Improve the throughput of our server with a thread pool. | |
22 | ||
23 | But before we get started, we should mention one detail: the method we’ll use | |
24 | won’t be the best way to build a web server with Rust. A number of | |
dc9dc135 XL |
25 | production-ready crates are available on [crates.io](https://crates.io/) that |
26 | provide more complete web server and thread pool implementations than we’ll | |
27 | build. | |
13cf67c4 XL |
28 | |
29 | However, our intention in this chapter is to help you learn, not to take the | |
30 | easy route. Because Rust is a systems programming language, we can choose the | |
31 | level of abstraction we want to work with and can go to a lower level than is | |
32 | possible or practical in other languages. We’ll write the basic HTTP server and | |
33 | thread pool manually so you can learn the general ideas and techniques behind | |
34 | the crates you might use in the future. |