10.1. HTTP connections

Intro to HTTP

HTTP stands for HyperText Transfer Protocol. It is used by two parties to transmit data between themselves over the Internet. For example, When you browse the web, your browser uses HTTP. The two parties are called:

  • Client: who requests data. For example, an app is requesting information about the user.

  • Server: who responds with the requested data. For example, the database server who responds to the app by sending the user information.

The request from a client: When a client sends a request to the server, it includes the following:

  • URL (Host/path): Uniform Resource Locator (URL) is the server's web address/IP address so that the client can locate it over the Internet.

  • Method: There are a few kinds of requests a client can make to the server:

    • GET: this method is used if a client wants to get some data from the server. This method is the most used one in real life.

    • POST: This method is used if a client wants to send some data to the server.

    • PUT: Similar to POST, the system admins often use PUT to update the database servers.

    • We will use GET and POST methods more than 99% of the time in real life.

    • There are other methods, like PUT and DELETE, which we will not discuss here.

  • Headers: the metadata a client can send to the server, where a client gives additional details for the request they are sending. For example, a header can hold the client's authentication token to prove the client's authenticity to the server.

  • Query String: If you noticed in real life, many websites have ? in their URLs when you browse. For example: http://example.com?q=test&state=MA.

    • Here the URL is http://example.com

    • After ? we have q=test and state=MA separated by &.

    • These are key-value pairs. In q=test, q is the key, and test is the value.

    • A client can send information to the server using these key-value pairs. The whole thing after ? is the query string.

  • Body: the body is the rest of the request. There is no limit to the body. A client can send additional information to the server using the request's body—for example, form data, JSON data, etc.

The server's response: A typical response from the server includes:

  • Status code: it indicates whether a specific HTTP request has been successfully completed.

    • Informational (100-199)

    • Successful (200-299)

    • Redirects (300-399)

    • Client errors (400-499)

    • Server errors (500-599)

    • You have probably seen the error 404 at some point in your cyber life. The 400-level codes usually mean the request the client sent was invalid.

    • 500-level codes are also pretty common. It means the request was correct, yet the server failed to execute properly to process the request.

    • 200-level codes are the most common, and usually, we don't see them in our browsers because they indicate a successful response.

  • Body: the response from the server comes as a part of the body.

  • Headers: SImilar to the request headers, server may use headers to send additional meta data.

Last updated

Was this helpful?