HTTP

The Hyper Text Transfer Protocol (HTTP) is one of most widely used application protocols for communicating over the internet. HTTP is a request-response, client-server protocol, where a client sends a request to a server for information and the server respond with the results.

HTTP is a stateless protocol. When a client sends a request to the server, it maintains a connection with the server only until the server responds or a connection times out. For each request, a new connection must be established. With the help of the diagram in Figure 3.3, let's understand response-request architecture:

Figure 3.3

The client sends a request to the server. A request consists of the HTTP version, HTTP method, URL, and arguments or the message body:

  • The Uniform Resource Locator (URL) consists of four parts:
    • Protocol: It is the application-level protocol used by the client for sending the request to the server
    • Hostname: It is the IP address of the server
    • Port: The TCP port on which the specific application is running on the server
    • Path: It is the path to the specific resource under the target application
  • A message body/argument can be text or JSON data that contains information about the client, such as sensor data or customer information, which is being sent to the server as part of the request.
  • The URL and message combine to form an HTTP request which is sent to the server over TCP/IP.

The two most commonly used HTTP methods for sending requests are:

  • GET: It is used only to retrieve data/information from server without modifying it
  • POST: It is used to send data to server such as the status of the device, customer information, and other such details

The server receives and parses the request. Based on the port and path, it maps it to the correct resource and after performing the necessary computation, it prepares the response and sends it back to the client.

The response consists of the status code and the message body. As shown in Figure 3.3, the response will have the status code 200 Ok and the message body containing the result expected by the client.

Common response code types are:

  • 2xx: Success
  • 4xx: Client error
  • 5xx: Server error
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.29.89