Sobes.tech
Junior

What does an HTTP request look like?

sobes.tech AI

Answer from AI

An HTTP request consists of the following parts:

  1. Request Line: Defines the request type, resource path, and protocol version.
  2. Headers: Additional information about the request, client, or request body.
  3. Blank line: Separates headers and request body.
  4. Request Body (optional): Contains data sent to the server (e.g., in POST requests).

Example of a GET request:

// Request line: method, path, protocol version
// GET /index.html HTTP/1.1

// Headers: information about the client, request, etc.
// Host: www.example.com
// User-Agent: Mozilla/5.0
// Accept: text/html

// Blank line: separates headers from body (none in this case)

// Request body (empty for GET)

Example of a POST request:

// Request line
// POST /submit HTTP/1.1

// Headers
// Host: www.example.com
// Content-Type: application/x-www-form-urlencoded
// Content-Length: 25

// Blank line

// Request body
// name=test&value=data

Main HTTP methods:

Method Description Has request body
GET Requests data from the specified resource No
POST Sends data to be processed to the specified resource Yes
PUT Replaces all current representations of the resource with the request data Yes
DELETE Deletes the specified resource No
HEAD Requests headers like GET but without response body No
PATCH Applies partial modifications to the resource Yes
OPTIONS Describes communication options for the target resource Optional
What does an HTTP request look like? — Python - sobes.tech