Systems Engineering: HTTP Request-Response Model

The Request-Response Model

The Request-Response Model is a fundamental communication pattern used in network protocols such as HTTP (HyperText Transfer Protocol), where a client (a browser or web app) sends a request to a server, and the server processes this request and sends back a response.

The communication starts when the client requests data from the server and ends when the server sends a response.

How It Works

Client Request

The client, which is usually an app, starts the communication by sending an HTTP request to the server. Typically, the request consists of a URL (endpoint), HTTP method (POST, GET, PUT, DELETE), Headers, and a Body (in POST and PUT requests).

  • URL: Specifies the resource being requested.

  • HTTP Method: Defines the action to be performed. Common methods include:

    • GET: Retrieve data from the server.
    • POST: Submit data to the server.
    • PUT: Update existing data on the server.
    • DELETE: Remove data from the server.
    • HEAD: Retrieve headers for a resource without the body.
    • OPTIONS: Describe the communication options for the target resource.
    • PATCH: Apply partial modifications to a resource.
  • Headers: Provide additional information about the request, such as content type, user agent, and authorization tokens.

  • Body: Contains the data being sent to the server, typically used in POST and PUT requests.

Server Parsing

The server receives the request and parses it to understand the request. This involves steps like validating the request, identifying the HTTP method to determine the action the server will take, extracting metadata from the headers, parsing query strings, processing cookies, and parsing the body.

Server Processing

After the request is parsed, the server performs actions based on the type of request. These actions could include querying a database, fetching a resource, or running a complex algorithm to process data.

Server Response

The server sends a response back to the client to complete and end the communication. The response typically consists of a Status Code, Headers, and a Body.

  • Status Code: Indicates the result of the request. Common status codes include:
    • 1xx Informational:

      • 100 Continue: The server has received the request headers, and the client should proceed to send the request body.
      • 101 Switching Protocols: The requester has asked the server to switch protocols, and the server has agreed to do so.
      • 102 Processing: The server has received and is processing the request, but no response is available yet.
    • 2xx Success:

      • 200 OK: The request was successful.
      • 201 Created: The request was successful and a resource was created.
      • 202 Accepted: The request has been accepted for processing, but the processing has not been completed.
      • 203 Non-Authoritative Information: The request was successful but the returned meta-information is from a cached copy instead of the server.
      • 204 No Content: The server successfully processed the request and is not returning any content.
      • 205 Reset Content: The server successfully processed the request, but is not returning any content, and requires that the requester reset the document view.
      • 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.
    • 3xx Redirection:

      • 300 Multiple Choices: There are multiple options for the resource that the client may follow.
      • 301 Moved Permanently: The resource has been moved permanently to a new URL.
      • 302 Found: The resource has been temporarily moved to a different URL.
      • 303 See Other: The response to the request can be found under another URL.
      • 304 Not Modified: The resource has not been modified since the last request.
      • 305 Use Proxy: The requested resource is only available through a proxy, whose address is provided in the response.
      • 307 Temporary Redirect: The resource has been temporarily moved to a different URL.
      • 308 Permanent Redirect: The resource has been permanently moved to a different URL.
    • 4xx Client Error:

      • 400 Bad Request: The server could not understand the request due to invalid syntax.
      • 401 Unauthorized: The client must authenticate itself to get the requested response.
      • 402 Payment Required: Reserved for future use.
      • 403 Forbidden: The client does not have access rights to the content.
      • 404 Not Found: The server can not find the requested resource.
      • 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.
      • 406 Not Acceptable: The server cannot produce a response matching the list of acceptable values defined in the request's headers.
      • 407 Proxy Authentication Required: The client must authenticate itself with the proxy.
      • 408 Request Timeout: The server would like to shut down this unused connection.
      • 409 Conflict: The request conflicts with the current state of the server.
      • 410 Gone: The requested resource is no longer available and will not be available again.
      • 411 Length Required: The request did not specify the length of its content, which is required by the requested resource.
      • 412 Precondition Failed: The server does not meet one of the preconditions that the requester put on the request.
      • 413 Payload Too Large: The request is larger than the server is willing or able to process.
      • 414 URI Too Long: The URI provided was too long for the server to process.
      • 415 Unsupported Media Type: The media format of the requested data is not supported by the server.
      • 416 Range Not Satisfiable: The range specified by the Range header field in the request can't be fulfilled.
      • 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.
      • 418 I'm a teapot: This code was defined in 1998 as one of the traditional IETF April Fools' jokes and is not expected to be implemented by actual HTTP servers.
      • 421 Misdirected Request: The request was directed at a server that is not able to produce a response.
      • 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.
      • 423 Locked: The resource that is being accessed is locked.
      • 424 Failed Dependency: The request failed because it depended on another request and that request failed.
      • 426 Upgrade Required: The client should switch to a different protocol.
      • 428 Precondition Required: The origin server requires the request to be conditional.
      • 429 Too Many Requests: The user has sent too many requests in a given amount of time ("rate limiting").
      • 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.
      • 451 Unavailable For Legal Reasons: The user requested a resource that cannot legally be provided, such as a web page censored by a government.
    • 5xx Server Error:

      • 500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
      • 501 Not Implemented: The server does not support the functionality required to fulfill the request.
      • 502 Bad Gateway: The server, while acting as a gateway or proxy, received an invalid response from the upstream server.
      • 503 Service Unavailable: The server is not ready to handle the request.
      • 504 Gateway Timeout: The server, while acting as a gateway or proxy, did not get a response in time from the upstream server.
      • 505 HTTP Version Not Supported: The HTTP version used in the request is not supported by the server.
      • 506 Variant Also Negotiates: The server has an internal configuration error.
      • 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.
      • 508 Loop Detected: The server detected an infinite loop while processing a request.
      • 510 Not Extended: Further extensions to the request are required for the server to fulfill it.
      • 511 Network Authentication Required: The client needs to authenticate to gain network access.

Summary

  • The Request-Response Model is a communication pattern used in HTTP.
  • The communication is initiated by the client and completed by the server.
  • The model consists of four key steps: Client Request, Server Parsing, Server Processing, and Server Response.