Understand the distinction between a client and a server. Grasp the request-response cycle. Examine the line-based structure of HTTP requests and responses. Configure a basic HTTP parser and implement a straightforward API.
Examples
Exercises
Context
In a distributed system, multiple systems must communicate with one another. On the web, a client (e.g. a browser or a server) wants to communicate with a server (e.g. a web service). To facilitate this, the server provides an application programming interface (API). These APIs can be implemented using various architectural styles and technologies.
The Request-Response Pattern is a communication pattern between two systems, where one system (the client) sends a request to the other system (the server) and the server responds with a response. This pattern is the basis for communication between a client and a server in a distributed system. The request contains information about the operation that should be performed and the parameters for the operation. The response contains the result of the operation. The request-response pattern is synchronous, which means that the client blocks until the server sends a response.
The Hypertext Transfer Protocol (HTTP) is the protocol used to communicate between a client and a server on the web. It is used to request and receive web pages, media files, and other resources from web servers. It is originally defined in the RFC 2616:
RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
HTTP is a line-based protocol that interprets text (see Network Socket).
A request starts with a request-line, followed by the header fields. A CRLF
, which is a new line character, separates the header from the body.
RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
In the following case, the body is a JSON document:
POST /todos HTTP/1.1
Host: todoapp.org
User-Agent: Mozilla/5.0 (Macintosh)
Accept: application/json
Connection: keep-alive
{ text: "Buy new groceries" }
Let’s send a manual request using a TCP socket connection as shown in:
topics/http/files · main · hs-heilbronn / fankhauser · GitLab