Understanding HTTP request methods is fundamental for backend, frontend, and full-stack developers. Below is a curated list of common interview questions covering core concepts, safety, caching, and RESTful API design.
1. What are the most common HTTP request methods and their primary purposes?
| Method | Primary Purpose | Request Body | Response Body |
|---|---|---|---|
| GET | Retrieve data from a server | Optional (discouraged) | Yes |
| POST | Submit data to create a new resource or trigger processing | Yes | Yes |
| PUT | Replace an entire existing resource (or create it at a known URI) | Yes | Optional |
| PATCH | Partially update an existing resource | Yes | Optional |
| DELETE | Remove a specified resource | Optional | Optional |
| HEAD | Retrieve response headers only (identical to GET without the body) |
No | No |
| OPTIONS | Describe communication options or CORS preflight permissions | No | Yes |
| CONNECT | Establish a network tunnel (commonly used for HTTPS via an HTTP proxy) | No | Optional |
| TRACE | Perform a message loop-back test along the path to the target resource | No | Yes |
![]()
2. What is the difference between a "Safe" method and an "Idempotent" method?
- Safe Methods: An HTTP method is safe if it does not alter the state of the server. In other words, it is strictly read-only.
- Safe methods:
GET,HEAD,OPTIONS,TRACE
- Safe methods:
- Idempotent Methods: An HTTP method is idempotent if making the same request multiple times produces the exact same server state as making it once (though response status codes may differ, e.g.,
200 OKon the firstDELETEand404 Not Foundon the second).- Idempotent methods:
GET,HEAD,OPTIONS,TRACE,PUT,DELETE
- Idempotent methods:
Key Takeaway: All safe methods are idempotent, but not all idempotent methods are safe. For example,
DELETEmodifies server state (not safe), yet deleting the same resource twice leaves the server in the same state (idempotent).POSTandPATCHare neither safe nor guaranteed to be idempotent.
3. What is the difference between PUT and PATCH?
PUT(Full Replacement): Replaces the entire target resource with the request payload. If a field is omitted in aPUTrequest, it should be reset tonullor its default value.PUTis idempotent.PATCH(Partial Modification): Applies partial modifications to a resource using a set of instructions (such as JSON Merge Patch or JSON Patch). Only the fields provided in the payload are updated.PATCHis not strictly idempotent (e.g., an operation like{"increment": 1}changes the state on every call), though it can be designed to be idempotent.
Example:
Suppose a user object is { "id": 1, "name": "Alice", "role": "admin" }:
PUT /users/1with{ "name": "Bob" }replaces the whole record, resettingroletonull.PATCH /users/1with{ "name": "Bob" }updates onlynameand keeps"role": "admin".
4. What is the difference between GET and POST?
| Feature | GET |
POST |
|---|---|---|
| Intent | Fetch/read data | Create resources or submit data for processing |
| Data Location | Query string in the URL (?key=value) |
Request body (JSON, form-data, multipart, etc.) |
| Idempotent & Safe | Yes / Yes | No / No |
| Caching | Cacheable by browsers and CDNs by default | Not cached by default unless explicit Cache-Control headers are set |
| History & Bookmarks | URLs with parameters can be bookmarked and appear in browser history | Request body is not saved in browser history or bookmarks |
| Data Size Limits | Constrained by browser/server URL length limits (typically 2KB–8KB) | Practically unlimited (governed by server configuration) |
5. Why is PATCH not considered idempotent by default?
While simple field assignments via PATCH (like {"status": "active"}) are idempotent, the HTTP specification (RFC 5789) defines PATCH as a set of delta instructions rather than a state snapshot. Because a PATCH payload can represent relative transformations—such as appending an item to an array or incrementing a counter—executing the exact same PATCH request multiple times can produce different server states.
6. How is the HEAD method used in real-world applications?
HEAD asks for a response identical to a GET request, without the response body. Common use cases include:
- Checking Resource Existence & Validity: Verifying whether a URL returns
200 OKor404 Not Found(e.g., link checkers) without downloading large payloads. - Inspecting Metadata Before Downloading: Checking
Content-Length(file size) orContent-Typebefore initiating a heavy file download. - Cache Validation: Reading
ETagorLast-Modifiedheaders to check if a cached resource has changed.
7. What role does the OPTIONS method play in CORS?
In Cross-Origin Resource Sharing (CORS), browsers automatically send an HTTP OPTIONS request—known as a preflight request—before making certain cross-origin requests (such as PUT, DELETE, or POST with Content-Type: application/json or custom headers like Authorization).
The preflight request includes headers like Access-Control-Request-Method and Access-Control-Request-Headers. The server responds with Access-Control-Allow-Methods, Access-Control-Allow-Origin, and Access-Control-Allow-Headers to confirm whether the actual request is permitted.
8. Can a GET request have a request body?
Technically, the HTTP/1.1 specification (RFC 9110) does not strictly forbid a GET request from containing a body, but it has no defined semantics. Most reverse proxies, CDNs, load balancers, and web frameworks either ignore, strip, or reject (400 Bad Request) a body on a GET request. If you need to send complex filter payloads, either encode them in query parameters or use POST (e.g., POST /search).
9. How do HTTP methods affect caching?
GETandHEADresponses are cacheable by default by browsers, CDNs, and reverse proxies when accompanied by appropriate freshness headers (Cache-Control,Expires,ETag).POSTresponses are only cacheable if explicit freshness headers (Cache-Control: max-age=...) and aContent-Locationheader are provided, though almost no shared caches storePOSTresponses in practice.PUT,PATCH, andDELETEare never cached—and in standard HTTP caches (like CDNs and browsers), a successfulPUT,PATCH, orDELETErequest to a URI automatically invalidates any cachedGET/HEADresponses for that same URI.
10. Why should the TRACE method be disabled in production?
TRACE echoes back the exact HTTP request received by the server in the response body. While intended for network diagnostics, leaving TRACE enabled in production exposes applications to Cross-Site Tracing (XST) attacks, where malicious scripts can read sensitive headers (such as Authorization tokens or cookies) that would otherwise be inaccessible via HttpOnly protections.