HTTP Request

================

An HTTP (Hypertext Transfer Protocol) request is the initial step in transferring data over the internet from a client to a server. The purpose of an HTTP Request is to send a message to the server, which then responds with a message back to the client.

Types of HTTP Requests


GET Request

A GET Request is used to retrieve data from a web server. It is the most common type of HTTP Request and is used for retrieving static resources such as HTML pages, images, and stylesheets.

  • URL Structure: http://example.com/path/to/resource
  • Request Headers:
    • Accept: Specifies the format of the response. (e.g., text/html)
    • Referer: Specifies the URL from which to retrieve the current page.
  • Request Body: None

POST Request

A POST Request is used to send data to a web server for processing. It is often used when the client needs to create, update, or delete resources.

  • URL Structure: http://example.com/path/to/resource
  • Request Headers:
    • Content-Type: Specifies the format of the request body.
    • X-Forwarded-For: Specifies the IP address of the client.
  • Request Body: JSON, XML, or plain text

PUT/PATCH Request

A PUT/PATCH Request is used to update an existing resource. It is often used when the client needs to update a single resource.

  • URL Structure: http://example.com/path/to/resource
  • Request Headers:
    • Content-Type: Specifies the format of the request body.
    • If-None-Match: Specifies the ETag of the response if an item is updated.
  • Request Body: JSON or XML

DELETE Request

A DELETE Request is used to delete a resource. It is often used when the client needs to remove a single resource.

  • URL Structure: http://example.com/path/to/resource
  • Request Headers:
    • If-None-Match: Specifies the ETag of the response if an item is updated.
  • Request Body: None

HTTP Request Methods


GET

GET is used to retrieve data from a web server. It can be used for retrieving static resources.

  • HTTP Method: GET
  • Method Parameters:
    • path: Specifies the URL of the resource.
  • Request Body: None

POST

POST is used to send data to a web server for processing. It is often used when the client needs to create, update, or delete resources.

  • HTTP Method: POST
  • Method Parameters:
    • content: Specifies the request body.
  • Request Body: JSON or XML

PUT/PATCH

PUT and PATCH are used to update an existing resource. They can be used for both creating and updating resources.

  • HTTP Method: PUT/PATCH
  • Method Parameters:
    • path: Specifies the URL of the resource.
    • content: Specifies the updated request body.
  • Request Body: JSON or XML

DELETE

DELETE is used to delete a resource. It can be used for both deleting existing resources and creating new ones.

  • HTTP Method: DELETE
  • Method Parameters:
    • path: Specifies the URL of the resource.
  • Request Body: None

HTTP Response


200 OK

The response indicates that the request was successful and the data can be used by the client.

  • Status Code: 200
  • Response Headers:
    • Content-Type: Specifies the format of the response.
  • Response Body: JSON or XML

400 Bad Request

The response indicates that the request was invalid or cannot be processed due to an error in the client’s request.

  • Status Code: 400
  • Response Headers:
    • Content-Type: Specifies the format of the response.
  • Response Body: JSON or XML

401 Unauthorized

The response indicates that the user lacks authorization to access the requested resource.

  • Status Code: 401
  • Response Headers:
    • Content-Type: Specifies the format of the response.
  • Response Body: JSON or XML

403 Forbidden

The response indicates that the client does not have permission to access the requested resource.

  • Status Code: 403
  • Response Headers:
    • Content-Type: Specifies the format of the response.
  • Response Body: JSON or XML

404 Not Found

The response indicates that the requested resource cannot be found on the server.

  • Status Code: 404
  • Response Headers:
    • Content-Type: Specifies the format of the response.
  • Response Body: JSON or XML

HTTP Header Fields


Accept

Specifies the format of the response. (e.g., text/html)

  • Value: string (e.g., text/html)
  • Description: The type of data to be received.

Authorization

Specifies the authentication method used to access the requested resource.

  • Value: string (e.g., Basic, Digest)
  • Description: The authentication scheme used to authenticate the client.

Cache-Control

Controls caching behavior in web browsers and intermediate servers.

  • Value: string
  • Description: Specifies caching policies for the response.

Connection

Specifies the connection type between the client and server. (e.g., keep-alive, close)

  • Value: string (e.g., persistent, no-cache)
  • Description: Specifies the connection mode used by the request.

Content-Type

Specifies the format of the request body. (e.g., application/json)

  • Value: string
  • Description: The type of data to be sent in the response.

ETag

Specifies the entity tag for the requested resource.

  • Value: string
  • Description: A unique identifier for the resource, which can be used to determine whether the request was successful or not.

If-None-Match

Specifies the ETag of an item that is updated in response to a PUT/PATCH Request. (e.g., text/html)

  • Value: string
  • Description: The ETag of the requested resource if it has been updated.

If-Match

Specifies the ETag of an item that matches the current version of the requested resource. (e.g., text/html)

  • Value: string
  • Description: The ETag of the requested resource if it is a copy.

Location

Specifies the URL of the requested resource if the requested resource can be found on the server.

  • Value: string
  • Description: The URL of the requested resource.

Pragma

Specifies an HTTP protocol version or mechanism that is supported by certain clients. (e.g., HTTP/1.0)

  • Value: string
  • Description: Specifies the HTTP protocol version used by the client.

Proxy-Authorization

Specifies a proxy’s authentication method when establishing connections to the server.

  • Value: string
  • Description: The authentication scheme used by the proxy.

Referer

Specifies the URL from which to retrieve the current page. (e.g., http://example.com)

  • Value: string
  • Description: Specifies the URL of the requesting resource.

User-Agent

Specifies the client’s software and version information when sending HTTP requests.

  • Value: string
  • Description: The user agent string used to identify the client.