ITPE001 - APIs

Web Request and Response

Publish Date:

What is HTTP?

HTTP or Hypertext Transfer Protocol is an application layer protocol that allows web-based applications to communicate and exchange data between each other.

Understanding the HTTP Request and Response Cycle

  1. When a user search or access a website it starts a chain of events that allow various devices or software to communicate with each other. This is done by done by a user on a client device or software (a web browser for example) by creating a string or a URL.
  2. The URL is then read by the software on the client’s device and then the browser will create a request for the URL that the user typed in the browser (https://mndrewdevlog.web.app/) The client will send an HTTP request to the server with the following information: HTTP Method, Requested Resource, Resource Headers.
  3. The Server receives the HTTP request and processes it.
    1. The server will check if the request is valid and will generate a response.
  4. The Server sends an HTTP response to the client together with the following information:
    • HTTP Status Code
    • Response Headers
    • Response Body
  5. The client receives the HTTP response and processes it.
    • If the request is successful, it will show the response body or the requested resource.
    • However, if the response it is unsuccessful an error message will be displayed.
      • Example - Error 404: Page or Resource Not Found

Definition of Terms

  • Client
    • a computer device or software that tries to access a resource from a server.
  • Server
    • a computer or software that provides resources to other computers called clients.
  • Path
    • A path is a part of the URL (Uniform Resource Locator)
    • This specifies the location of a specific resource on the server.

    Example

  • Verb
    • In HTTP a verb pertains to an HTTP Method or HTTP Verb.
    • A verb specifies what action is going to be performed on the resource
    • List of HTTP Verbs
      • GET
      • PUT
      • POST
      • PUT
      • CONNECT
      • PATCH

What are the common HTTP verbs and what do they do?

Here are 5 common HTTP verbs with their respective operations or Function

VerbOperations/Function
GETThis method requests a specific resource from the web server.
POSTThis method submits data or information to a specific resource.
DELETEThis method deletes a specific resource
PATCHThis method updates a resource
CONNECTThis method allows a connection tunnel to the server to a specific resource.

Response Status Code Categories

As part of the HTTP Request and Response cycle status codes help indicate whether a request has been completed.

The status codes are categorized into 5 cases with each specific use case.

HTTP Status Code RangePurpose or CategoryExample
100 - 199Informational Responses100 - Continue
200 - 299Successful Responses200 - OK or Successful
300 - 399Redirect Message302 - Redirected
400 - 499Client Error Message404 - Not Found
500 - 599Server Error Message502 - Bad Gateway

References