This chapter covers:
- Writing a TCP server in Rust
- Writing an HTTP server in Rust
In this chapter, you will delve deep into TCP and HTTP communications using Rust.
These protocols are generally abstracted away for developers through higher-level libraries and frameworks used to build web applications. So, why is it important to discuss low level protocols? This would be a fair question.
Learning to work with TCP and HTTP is important because they form the foundation for most communications on the Internet. Popular application communication protocols such as REST, gRPC, websockets and TLS use HTTP and TCP for transport. Designing and building basic TCP and HTTP servers in Rust gives the confidence to design, develop and troubleshoot higher-level application backend services.
However, if you are eager to get started with the example application, you can move to Chapter 3, and later come back to this chapter at a time appropriate for you.
In this chapter, you will learn the following:
- Write a TCP client and server.
- Build a library to convert between TCP raw byte streams and HTTP messages.
- Build an HTTP server that can serve static web pages (aka web server) as well as json data (aka web service). Test the server with standard HTTP clients such as cURL (commandline) tool and web browser.