]> git.proxmox.com Git - rustc.git/blob - src/doc/book/src/ch20-00-final-project-a-web-server.md
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / src / ch20-00-final-project-a-web-server.md
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 our plan for building 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 Before we get started, we should mention one detail: the method we’ll use won’t
24 be the best way to build a web server with Rust. Community members have
25 published a number of production-ready crates available on
26 [crates.io](https://crates.io/) that provide more complete web server and
27 thread pool implementations than we’ll build. However, our intention in this
28 chapter is to help you learn, not to take the easy route. Because Rust is a
29 systems programming language, we can choose the level of abstraction we want to
30 work with and can go to a lower level than is possible or practical in other
31 languages. We’ll therefore write the basic HTTP server and thread pool manually
32 so you can learn the general ideas and techniques behind the crates you might
33 use in the future.