HTTP Interview Questions and Answers

HTTP Interview Questions and Answers - EncodingCompiler

Quick answer

HTTP (Hypertext Transfer Protocol) is the application-layer protocol browsers and servers use to exchange web resources: a client sends a request with a method such as GET or POST, and the server returns a response with a status code such as 200 OK or 404 Not Found. HTTP interviews focus on request methods, status codes, idempotent and safe methods, statelessness, persistent connections and HTTPS.

HTTP is the foundation of how browsers and servers talk on the web, so it comes up in almost every web development and backend interview. This guide covers the questions interviewers ask most often, from basic concepts to status codes and request methods, with short answers you can adapt in your own words.

Most Frequently Asked HTTP Interview Questions and Answers

  • What is HTTP?
  • What is an HTTP session?
  • What are the different HTTP request methods?
  • What is an idempotent method?
  • What are persistent connections?
  • What is a secure HTTP connection?
  • What does cURL do in HTTP?
  • What do the 201, 404 and 500 status codes mean?

1. What is HTTP?

HTTP (Hypertext Transfer Protocol) is the application-layer protocol that clients and servers use to exchange resources on the World Wide Web. A client sends a request, and the server returns a response.

2. What is an HTTP session?

An HTTP session is one request-response exchange between a client and a server. The client opens a TCP connection to the server, sends a request, and the server replies with a status line followed by headers and, usually, a body.

3. What does an HTTP request message contain?

A request has three main parts:

  • Request line, such as GET /images/logo.png HTTP/1.1, which names the method, the resource, and the protocol version.
  • Headers, such as Accept-Language: en, which carry metadata about the request.
  • An optional body, used mostly with POST and PUT, separated from the headers by an empty line.

4. What are the main HTTP request methods?

HTTP interview questions and answers: HTTP Methods: Safe and Idempotent
HTTP Methods: Safe and Idempotent (quick reference)
  • GET retrieves a resource. Query parameters travel in the URL.
  • POST sends data to the server, usually to create a resource. The data goes in the request body.
  • PUT creates or replaces a resource at a known URL.
  • PATCH applies a partial modification to a resource.
  • DELETE removes a resource.
  • HEAD behaves like GET but returns only headers, with no body.
  • OPTIONS asks the server which methods and options are supported for a resource.

5. What is a safe method?

A safe method is one that should not change the state of the server’s resources. GET, HEAD and OPTIONS are considered safe. Calling them should only read data, never modify it.

6. What is an idempotent method?

An idempotent method produces the same server state no matter how many times it is called with the same input. GET, PUT and DELETE are idempotent. POST usually is not, because repeating it can create duplicate resources. A common interview example: sending the same PUT twice leaves the resource in the same final state, while sending the same POST twice may create two records.

7. What are HTTP status codes?

A status code is a three-digit number in the server’s response. The first digit identifies the class:

HTTP interview questions and answers: HTTP Status Code Classes
HTTP Status Code Classes (quick reference)
  • 1xx: informational. The request was received and processing continues.
  • 2xx: success. The request was received, understood and accepted.
  • 3xx: redirection. The client must take further action to complete the request.
  • 4xx: client error. The request is malformed or cannot be fulfilled.
  • 5xx: server error. The server failed to handle a valid request.

8. What are persistent connections?

A persistent connection, also called keep-alive or connection reuse, lets a client and server send several requests and responses over a single TCP connection instead of opening a new one each time. The connection closes after it sits idle for a configured period.

9. Is HTTP stateful?

No. HTTP is stateless, meaning the server does not keep information about a client between requests. Applications add state themselves, usually with cookies, tokens or server-side sessions.

10. How is a secure HTTP connection established?

There are two common approaches: using the HTTPS scheme, which wraps HTTP in TLS, or upgrading an existing HTTP/1.1 connection through the Upgrade header.

HTTP interview questions and answers: HTTP/1.1 vs HTTP/2 vs HTTP/3
HTTP/1.1 vs HTTP/2 vs HTTP/3 (quick reference)

11. What is the HTTPS URL scheme?

The scheme is the first part of a URL and tells the client which protocol to use. https:// means HTTP over TLS, which encrypts the traffic between client and server. http:// sends it unencrypted.

12. What makes up an HTTP message?

Every HTTP message has headers and, optionally, a body. Headers carry metadata such as content type, length and authentication details. The body carries the actual payload, if there is one.

13. What happens to undeliverable IP datagrams?

They are discarded, and the router or host that dropped them typically sends an ICMP error message back to the source.

14. What is cURL?

cURL is a command-line tool for transferring data with URLs. Developers use it to send HTTP requests, test endpoints, and inspect headers and responses. It is available on most operating systems.

15. What are HTTP verbs?

HTTP verbs, also called methods, tell the server what action to perform on the resource identified by the URL. Examples include GET, POST, PUT and DELETE.

16. What does a 500 Internal Server Error mean?

A 500 response is a general signal that the server hit an unexpected condition and could not complete the request. It usually points to a bug or misconfiguration on the server side.

17. What are representations in HTTP?

A representation is the data that describes a resource’s current or desired state, such as JSON, HTML or an image. Clients and servers exchange representations rather than the resource itself, and the representation tells the client how to interpret or use the resource.

18. What does 200 OK mean?

200 OK means the request succeeded and the response contains the requested data.

19. What does 201 Created mean?

201 Created means the request succeeded and a new resource was created as a result. It is typically returned after a successful POST or PUT, often with a Location header pointing to the new resource.

20. What does 400 Bad Request mean?

400 means the server could not process the request because it was malformed, for example when a POST or PUT body is not valid JSON or is missing required fields.

21. What does 404 Not Found mean?

404 means the server could not find the resource at the requested URL.

22. What does 401 Unauthorized mean?

401 means the client must authenticate before it can access the resource. Despite the name, it is about missing or invalid credentials, not permissions. A 403 Forbidden response means the server knows who the client is but will not allow the action.

23. What does 405 Method Not Allowed mean?

405 means the resource exists but does not support the HTTP method used. For example, sending DELETE to a URL that only accepts GET.

24. What does 409 Conflict mean?

409 means the request conflicts with the current state of the resource, such as trying to create a record with a duplicate unique key.

25. Which OSI layer does IP belong to?

IP operates at the network layer (layer 3) of the OSI model.

26. Why is IP described as unreliable?

IP makes a best-effort attempt to deliver packets but does not guarantee delivery, ordering or duplicate protection. Reliability is handled by higher-level protocols such as TCP.

27. What are the two roles in HTTP?

The client initiates every exchange by sending a request, and the server responds to it.

Conclusion

These questions cover the core of HTTP that most interviewers expect you to know. Practice explaining each method and status code in your own words, and try a few requests with cURL or your browser’s developer tools to see the concepts in action. If you have recently been asked questions that are not listed here, share them in the comments and we can work through the answers together.

Sources and further reading

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *