Autocoder

HTTP and HTTPS Interview Questions: Methods, Status Codes, TLS and Caching

Last updated 2026-11-19

HTTP questions appear in networking, backend and full-stack interviews alike. The expected depth is more than the list of verbs: which methods are safe and idempotent, what 301, 302, 304 and 429 mean in practice, how cookies and caching headers work, what changed in HTTP/2 and HTTP/3, and what happens during a TLS handshake. This page answers each with the exact behaviour and a few concrete requests.

For the transport underneath see TCP/IP interview questions and TCP vs UDP. Name lookups are covered in DNS interview questions, and the whole request path in what happens when you type a URL. For round preparation see how to crack a computer networks interview.

NumericalPage load time in RTTs for non-persistent, persistent and pipelined HTTP/1.1
CoveredMethods, status codes, headers, cookies, caching, CORS, HTTP/2, HTTP/3, TLS
Questions17

Safe and idempotent in one table

HTTP and HTTPS Interview Questions: questions with worked answers

  1. 1

    What is HTTP and what does it mean that HTTP is stateless?

    easy

    HTTP is the application-layer request-response protocol of the web, normally over TCP port 80, or port 443 when secured by TLS. Stateless means each request is self-contained: the server keeps no memory of previous requests on its own. State such as login is added with cookies, tokens or server-side sessions identified by an ID the client sends every time. Statelessness makes it easy to scale by adding servers behind a load balancer.

  2. 2

    What are the common HTTP methods and what is each used for?

    easy

    GET retrieves a resource, HEAD retrieves only headers, POST submits data or creates a resource, PUT replaces a resource at a known URL, PATCH applies a partial update, DELETE removes a resource, and OPTIONS asks which methods are allowed (and is used for CORS preflight). In REST APIs: GET /users/5 reads, POST /users creates, PUT /users/5 replaces, PATCH /users/5 updates fields, DELETE /users/5 deletes.

  3. 3

    What is the difference between PUT, POST and PATCH?

    medium

    POST sends data to a collection or handler and the server decides the resulting URL, so repeating it usually creates another resource. PUT sends a full representation to a specific URL, creating or replacing it, and repeating it gives the same result (idempotent). PATCH sends only the changes, so it is smaller but its idempotence depends on the patch format: set email = x is idempotent, increment counter is not.

  4. 4

    Explain the HTTP status code classes with common examples.

    easy

    1xx informational (101 Switching Protocols for WebSocket). 2xx success (200 OK, 201 Created, 204 No Content). 3xx redirection (301 Moved Permanently, 302 Found, 304 Not Modified, 307 and 308 preserve the method). 4xx client error (400 Bad Request, 401 Unauthorized meaning unauthenticated, 403 Forbidden, 404 Not Found, 409 Conflict, 429 Too Many Requests). 5xx server error (500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout).

  5. 5

    What is the difference between 401 and 403, and between 301 and 302?

    medium

    401 means the request lacks valid authentication, so logging in may fix it; 403 means the server understood who you are but refuses access. 301 is a permanent redirect, so browsers and search engines cache it and transfer ranking to the new URL; 302 is temporary, so the original URL remains canonical. 307 and 308 are the temporary and permanent redirects that guarantee the method and body are preserved, while 301 and 302 historically let clients change POST to GET.

  6. 6

    Show the structure of an HTTP request and response.

    medium

    A request has a request line (method, path, version), headers, a blank line and an optional body. A response has a status line (version, code, reason), headers, a blank line and the body. Headers such as Host, Content-Type, Content-Length, Authorization and Cookie carry metadata.

    text
    POST /api/login HTTP/1.1
    Host: example.com
    Content-Type: application/json
    Content-Length: 41
    
    {"user":"asha","password":"correct horse"}
    
    HTTP/1.1 200 OK
    Content-Type: application/json
    Set-Cookie: sid=abc123; HttpOnly; Secure; SameSite=Lax
    
    {"ok":true}
  7. 7

    How do cookies, sessions and tokens differ?

    medium

    A cookie is a small key-value pair that the server sets with Set-Cookie and the browser returns on every matching request. A session stores user state on the server and uses a cookie holding only a random session ID. A token such as a JWT carries signed claims in the token itself, so the server can verify it without a lookup, but revoking it before expiry is harder. Cookie flags matter: HttpOnly hides it from JavaScript, Secure restricts it to HTTPS, SameSite limits cross-site sending and helps against CSRF.

  8. 8

    Numerical: A page has a base HTML file and 10 small objects, RTT is 100 ms, and transmission time is negligible. Find the load time for non-persistent HTTP with no parallel connections, persistent HTTP without pipelining, and persistent with pipelining.

    medium

    Non-persistent: each object needs 1 RTT to open TCP plus 1 RTT for the request and response, so 11 x 2 = 22 RTT = 2.2 s. Persistent without pipelining: one TCP setup (1 RTT), then one RTT per object including the base file: 1 + 11 = 12 RTT = 1.2 s. Persistent with pipelining: 1 RTT for TCP, 1 RTT for the base file, then the 10 objects requested together in 1 RTT, so 3 RTT = 0.3 s. Browsers also open several parallel connections, and HTTP/2 multiplexing achieves the pipelined result more safely.

  9. 9

    What are the main differences between HTTP/1.1, HTTP/2 and HTTP/3?

    medium

    HTTP/1.1 is text-based with persistent connections, but one outstanding response per connection, so browsers open about six connections per host. HTTP/2 is binary, multiplexes many streams on one TCP connection, compresses headers (HPACK) and allows server push (rarely used now); one lost TCP packet stalls all streams. HTTP/3 runs over QUIC on UDP with per-stream loss recovery, built-in TLS 1.3 and faster connection setup and migration between networks.

  10. 10

    How does HTTP caching work? Explain Cache-Control, ETag and 304.

    medium

    Cache-Control: max-age=3600 lets a client or shared cache reuse a response for 3600 seconds without contacting the server. After it expires the client revalidates: it sends If-None-Match with the stored ETag (or If-Modified-Since). If nothing changed, the server replies 304 Not Modified with no body, saving bandwidth. no-store forbids storing, no-cache means store but always revalidate, and public or private says whether shared caches such as a CDN may keep it. Static assets are usually fingerprinted and cached for a year.

  11. 11

    What is CORS and why does the browser send an OPTIONS preflight request?

    medium

    The same-origin policy stops a page from reading responses from another origin (scheme, host, port). Cross-Origin Resource Sharing lets a server opt in with headers such as Access-Control-Allow-Origin. For requests that could change state (methods other than simple GET or POST, custom headers, JSON content type) the browser first sends an OPTIONS preflight asking if the real request is allowed, and only continues if the Access-Control-Allow-Methods and Headers permit it. CORS is enforced by browsers, not servers, so it does not protect an API from curl.

  12. 12

    What is the difference between HTTP and HTTPS?

    medium

    HTTPS is HTTP over TLS. TLS provides confidentiality (encryption), integrity (tampering is detected) and authentication of the server through a certificate signed by a trusted certificate authority. Without it, anyone on the path can read or alter traffic. HTTPS uses port 443, and HSTS (Strict-Transport-Security) tells browsers to use HTTPS only for that domain.

  13. 13

    Describe the TLS 1.3 handshake.

    medium

    The client sends ClientHello with supported ciphers and a key share (an ephemeral Diffie-Hellman public value). The server replies with ServerHello and its own key share; both sides now derive the session keys, and the rest of the handshake (the server certificate, a signature proving possession of the key, and Finished) is already encrypted. The client verifies the certificate chain and domain name, sends Finished, and application data flows. That takes one round trip after TCP; TLS 1.2 took two. Ephemeral keys give forward secrecy.

  14. 14

    How does a browser verify a certificate?

    medium

    The server sends its certificate and intermediates. The browser builds a chain from the leaf up to a root CA in its trust store, checking each signature, validity dates, that the hostname matches the certificate's subject alternative names, key usage, and revocation status (OCSP or CRL). If any check fails the browser shows a warning. The leaf's public key is then used to verify the handshake signature, which proves the server holds the private key.

  15. 15

    What are idempotent methods and why do they matter for retries?

    medium

    A method is idempotent if repeating the same request has the same effect on the server as sending it once. Clients, proxies and load balancers can safely retry GET, PUT and DELETE after a timeout. POST is not safe to retry blindly, so payment APIs accept an Idempotency-Key header and the server stores the result under that key, returning it on repeats.

  16. 16

    What is the difference between a forward proxy, a reverse proxy and a CDN?

    hard

    A forward proxy acts for clients (a corporate proxy, filtering or caching outbound requests). A reverse proxy such as nginx sits in front of servers: it terminates TLS, balances load, caches and hides the backends. A CDN is a geographically distributed set of reverse-proxy caches that serve content from a location near the user, using DNS or anycast to route to the nearest one, reducing latency and origin load.

  17. 17

    How do WebSockets and Server-Sent Events differ from normal HTTP requests?

    hard

    A normal request gets one response and ends. A WebSocket starts as an HTTP request with Upgrade: websocket, receives 101 Switching Protocols and then becomes a full-duplex message channel over the same TCP connection, suited to chat and live collaboration. Server-Sent Events keep an HTTP response open and stream text events one way from server to client over plain HTTP, with built-in reconnection. Long polling repeats requests and is the fallback.

Frequently asked questions

What is the difference between HTTP and HTTPS in one line?

HTTPS is HTTP carried inside a TLS-encrypted connection, adding encryption, tamper detection and server authentication through certificates.

What is the Host header for?

It tells the server which site the request is for, so one IP address can serve many domains (virtual hosting). It is mandatory in HTTP/1.1.

Which HTTP method should a login form use?

POST, with the credentials in the body over HTTPS. GET would place the password in the URL, which is saved in logs, browser history and the Referer header.

What is a REST API?

An architectural style using HTTP methods on resource URLs, stateless requests, standard status codes and representations such as JSON. It is a convention for designing APIs, not a protocol.

Related guides

More in CS Fundamentals Interview Questions

See all in this section