What is an HTTP request?
An HTTP request is a message that a client (browser, application, script) sends to a server over the HTTP protocol in order to get data or perform an action.
In simple terms: an HTTP request is the specific form a client's "ask" to a server takes under HTTP's rules.
Why an HTTP request is needed
An HTTP request is needed to:
- request a web page
- send form data
- get data from an API
- delete or change data on the server
Without an HTTP request the server does nothing: it always waits for a request from the client.
What happens during an HTTP request
- The client builds an HTTP request
- It sends the request to the server
- The server reads the request
- The server performs the needed action
- The server sends an HTTP response
The scheme is always the same:
HTTP request → HTTP response
What an HTTP request consists of (in simple terms)
An HTTP request usually contains:
1. Method, what to do
For example:
- get data
- send data
- delete a resource
(the best known: GET, POST, PUT, DELETE)
2. URL, what to address
The address of the resource on the server, for example:
- a page
- a file
- an API method
3. Headers, service information
For example:
- the data type
- authorization information
- data about the client
4. Request body, data
Not always sent:
- form data
- JSON for an API
- files
A simple example
When you open a site:
"Server, give me the page
/index.html"
That is an HTTP request.
When you submit a form:
"Server, here is the user's data, save it"
That is also an HTTP request, just with data inside it.
Key properties of an HTTP request
- always sent by the client
- the server never sends the request first
- each request is independent (HTTP is stateless)
Short answer for an interview
Remember this wording:
An HTTP request is a message sent by a client to a server over HTTP that contains information about the requested action, the resource, and the data being transferred.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.