HTTP & APIs Interview Questions: REST Idempotency

Reviewed by Mark Dickie · Last updated

14 questions on this page you can answer and see marked on the spot. Go to the first one

HTTP idempotency is a property where sending the same request more than once leaves the server in the same state as sending it a single time. Know which REST methods the HTTP spec calls idempotent (GET, HEAD, PUT, DELETE, OPTIONS) versus which it does not (POST, PATCH), and how that differs from safety. Idempotency keys are the other pattern to know: the header-based approach that lets a client retry a POST without creating a duplicate.

MethodSafeIdempotentTypical use
GETYesYesRead a resource
HEADYesYesRead headers only
OPTIONSYesYesDescribe capabilities
POSTNoNoCreate or non-safe action
PUTNoYesReplace a resource
DELETENoYesRemove a resource
PATCHNoNoPartial update

What is the difference between idempotent and safe HTTP methods?

A safe method does not modify server state. GET and HEAD are safe because reading a resource should never change it. Idempotency is a weaker guarantee: the method can change state, but repeating the call produces the same result each time. PUT and DELETE fit here. A DELETE on the same resource twice should end with the resource gone, whether the second call found it or returned 404.

How do idempotency keys make POST retries safe?

POST is not idempotent, so retrying it can create duplicate records or charges. An idempotency key lets the server deduplicate retries by storing the first response under a client-supplied key:

  1. Client generates a unique key, often a UUID, and sends it in the Idempotency-Key header on the POST request.
  2. Server processes the request and stores the response keyed by that ID before returning it, usually with a short TTL.
  3. On a retry with the same key, the server returns the stored response instead of re-running the operation.
  4. If the key is not found (expired or first seen), the server processes the request normally and stores the result.

Key facts

  • Tarmac's HTTP & APIs interview questions cover 25 questions at difficulty 1–5 of 5.
  • Tarmac tracked 2,497 job postings asking for HTTP & APIs in November 2026.
  • Roles asking for HTTP & APIs advertise a median base salary of £75,000, across 489 job postings as of November 2026.
  • Tarmac last reviewed these HTTP & APIs interview questions on 13 October 2026.

At a glance

Questions25
Difficulty1–5 of 5
FormatsTrue / false, Short answer, Multiple choice, Fill in the blank, Multiple answer, Find the bug

What you'll review

  1. idempotency

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

In REST API design, a GET request is idempotent: sending the same GET request several times has no additional server-side effect beyond the effect of sending it once. True or false?#

Options

Show answer

True. A GET request is idempotent under RFC 9110: repeating it is intended to have no additional server-side effect beyond the first request. Idempotency concerns server-side effects, not whether each response is byte-for-byte identical, since a GET to a changing resource can return different bodies.

Why:

Idempotency in RFC 9110 is about the intended server-side effect of repeated requests, not about whether every response is identical. A GET only retrieves a representation and is meant not to change server state, so repeating it adds no server-side effect beyond the first send. Responses may still differ over time (for example, a timestamp endpoint or a resource changed by another client), but that does not affect idempotency, so the statement is true.

Among the HTTP methods GET, PUT, DELETE, and POST, which one is NOT idempotent in REST API design? Answer with the method name.#

Show answer

POST is not idempotent because repeated identical POST requests can create duplicate resources or trigger repeated side effects on the server.

Why:

POST is the canonical non-idempotent HTTP method: each identical POST can create a new resource or trigger a new side effect, so repeating it changes the outcome. GET is a read-only retrieval, PUT replaces the same target resource state each time, and DELETE removes the same resource each time, all producing the same end state regardless of repetition. Restricting the question to these four methods avoids PATCH, whose idempotency depends on the patch document.

Which of the following HTTP methods is NOT idempotent?#

Options

Show answer

POST is the HTTP method that is not idempotent. Sending the same POST request several times typically creates a new resource each time, so the outcome differs from sending it once. GET, PUT, and DELETE all leave the server in the same state when repeated.

Why:

An idempotent HTTP method is one where sending the same request multiple times has the same effect as sending it once. GET, PUT, and DELETE are idempotent: repeated GETs return the same resource state, repeated PUTs set the resource to the same target state, and repeated DELETEs leave the resource deleted. POST is not idempotent because each request typically creates a new resource, so sending it twice creates two resources rather than one.

An HTTP method is called _____ if making the same request multiple times has the same effect on the server's state as making it a single time.#

Show answer

An HTTP method is called idempotent if making the same request multiple times has the same effect on the server's state as making it a single time.

Why:

Idempotency means that repeated identical requests do not change the server's resource state beyond the effect of the first request. This property lets clients safely retry a request (for example, after a network timeout) without worrying about duplicating side effects. GET, PUT, and DELETE are the classic idempotent methods, while POST is not.

Per the HTTP specifications (RFC 9110 and RFC 5789), which of these methods is defined as idempotent but not safe: PUT, POST, GET, or PATCH?#

Options

Show answer

PUT is the HTTP method defined as idempotent but not safe. RFC 9110 defines PUT as idempotent because repeating the same request leaves the same server state, and PUT is not safe because it is meant to modify the target resource.

Why:

RFC 9110 defines PUT as idempotent: sending the same PUT request repeatedly leaves the target resource in the same state as one request does. PUT is not safe because its purpose is to change server state. GET is excluded because it is safe; RFC 9110 says safe methods are also idempotent, so GET is not 'idempotent but not safe'. POST is not defined as idempotent, since each request may create a new resource. PATCH is defined by RFC 5789 as neither safe nor idempotent, so it does not fit either. Only PUT satisfies both conditions of being idempotent and not safe.

According to RFC 9110 (HTTP Semantics), which HTTP request methods are defined as idempotent? List all of them. Then explain why POST is not idempotent, and why PATCH (defined in RFC 5789, not RFC 9110) is not guaranteed to be idempotent.#

Show answer

Per RFC 9110, the idempotent methods are GET, HEAD, OPTIONS, TRACE, PUT, and DELETE. Idempotent means that sending the same request multiple times has the same intended effect on server state as sending it once. The safe methods (GET, HEAD, OPTIONS, TRACE) do not change state at all, and PUT (replace the whole target representation) and DELETE (remove the target) reach the same end state on repetition. POST is not idempotent because each request typically asks the server to create a new subordinate resource, so repeats create duplicates. RFC 5789 defines PATCH as neither safe nor idempotent: a patch document can describe relative changes (for example, append an item or increment a counter), so applying it twice can produce a different state than applying it once.

Why:

RFC 9110 states that PUT, DELETE, and the safe methods are idempotent; the safe methods are GET, HEAD, OPTIONS, and TRACE, giving six idempotent methods in total. Idempotency is judged by the effect on server state, so repeated identical requests must leave the same end state as one request. POST is not idempotent because it typically creates a new subordinate resource on each request, so repetition creates more resources. PATCH is not idempotent by definition in RFC 5789 because a patch document may express relative changes such as appending or incrementing, whose effects accumulate when repeated.

Which statement about HTTP idempotency is correct?#

Options

Show answer

PUT is idempotent: repeating an identical PUT request leaves the resource in the same state as a single request. Idempotency concerns the effect on server-side state, so PUT stays idempotent even when it creates a resource. POST and PATCH do not carry that guarantee in general.

Why:

Idempotency means that repeated identical requests have the same effect on server-side state as a single request. PUT meets this even when it creates a resource, because every identical PUT leaves the resource in the same state. POST can create duplicate records when repeated, and PATCH is not guaranteed idempotent by its definition, since only some PATCH operations (such as full replacement) are. Idempotency concerns the effect on state rather than the response body, so requiring identical response bodies is not part of the definition.

Under RFC 9110, a method is idempotent if multiple identical requests leave server-side resource state the same as a single request, even when the responses carry different status codes (for example, the first DELETE returns 200 and a repeated DELETE returns 404). True or false: under this definition, DELETE is idempotent.#

Options

Show answer

True. RFC 9110 defines idempotency by its effect on server-side resource state, not by the response code returned. Repeated DELETE requests leave the resource absent just as a single DELETE does, so a first 200 followed by a 404 does not break idempotency.

Why:

The statement is true. RFC 9110 defines idempotency by the effect a request has on server-side resource state, not by the response it receives. Repeating a DELETE leaves the resource absent in the same way as a single DELETE, so the state is identical. The first request returning 200 and a repeat returning 404 does not change that, so DELETE is idempotent.

Per the HTTP specification (RFC 9110), sending an Idempotency-Key header with a POST request makes the POST method itself idempotent. Is this statement true or false?#

Options

Show answer

False. Adding an Idempotency-Key header does not make the POST method idempotent under the HTTP specification. RFC 9110 defines idempotent methods such as GET, PUT, and DELETE, and POST is not among them. The key is an application-level convention that lets the server detect duplicate requests and return the stored response.

Why:

RFC 9110 lists the idempotent methods as GET, HEAD, OPTIONS, TRACE, PUT, and DELETE; POST is not one of them, and no header defined in the specification changes that. The Idempotency-Key header is a de facto convention popularized by payment APIs such as Stripe, not part of HTTP/1.1, HTTP/2, or RFC 9110-9114. It does not alter the formal semantics of POST. The guarantee comes from server-side logic: the server stores the response for a given key and replays it for duplicate requests instead of re-executing the operation. The statement is therefore false.

Per RFC 9110, which HTTP request methods are defined as idempotent — i.e., issuing the same request N times has the same effect on server state as issuing it once? (Idempotence is separate from safety; a method can be idempotent yet still cause state changes.)#

Show answer

Per RFC 9110 § 9.2.2, six request methods are defined as idempotent: GET, HEAD, OPTIONS, TRACE, PUT, and DELETE. GET, HEAD, OPTIONS, and TRACE are also safe (no server state change). PUT and DELETE are idempotent but not safe: PUT replaces the target resource with the supplied representation, so repeating the same PUT leaves the resource in the same state; DELETE requests removal of the target resource, so repeating the same DELETE has the same effect as doing it once. POST is not idempotent — each call may create a new resource or trigger a new side effect. PATCH (RFC 5789) is not defined as idempotent; depending on the patch semantics, repeated application can accumulate changes.

Why:

Per RFC 9110 § 9.2.2, the idempotent request methods are GET, HEAD, OPTIONS, TRACE, PUT, and DELETE. GET, HEAD, OPTIONS, and TRACE are also safe (read-only retrieval). PUT (full resource replacement) and DELETE (resource removal) are not safe but are idempotent because repeating the identical request leaves the resource in the same state. POST is explicitly not idempotent — each call can create a new resource or trigger a new side effect. PATCH (RFC 5789) is not classified as idempotent; depending on the patch semantics, repeated application can accumulate changes.

A REST API exposes POST /payments to charge a customer. A network timeout causes the client to retry the identical request, and the service runs on several instances and may restart. Explain how an Idempotency-Key header prevents a duplicate charge. In your answer, cover: (1) where the key and its outcome are stored, (2) how two concurrent retries carrying the same key are prevented from both charging, including what happens to a retry that arrives while the first request is still in flight, and (3) how the server handles a reused key that comes with a different request payload.#

Show answer

The client sends a unique Idempotency-Key (e.g., a UUID) with each logical operation. The server stores the key, a hash of the request payload, its state (in progress or completed), and the eventual response (status code and body) in a shared durable store such as a database, so every instance and any restart sees the same record. To prevent a race, the server first atomically reserves the key by inserting it under a unique constraint (or acquiring a row lock) before calling the charge; if the insert conflicts, a concurrent request is already handling it, so the server either rejects it while in progress (e.g., a conflict response) or waits for and replays the stored result once completed. Where the charge is recorded in the same database, the key row and the charge are written in one transaction so they succeed or fail together; when charging an external processor, the key is passed along and the processor's own idempotency handles that step. On a retry after completion, the server compares the stored payload hash with the incoming one: if identical, it returns the stored response without charging again; if different, it returns an error because the key was reused for a different operation.

Why:

The retry is safe because the server ties the client's unique key to the outcome of the first attempt, so a retry replays the stored response instead of charging again. Reliability requires more than checking for the key: the server must atomically reserve the key (for example with a unique constraint or a row lock) before charging, because a check-then-charge sequence lets two concurrent retries both see no key and both charge. A request that finds the key still in progress must be rejected or made to wait, and the key record should be written in the same transaction as the charge where the charge is local. The key and its response must live in a shared durable store, not process memory, so that a retry hitting another instance or arriving after a restart finds the record. Finally, storing a hash of the payload lets the server detect a reused key with different parameters and return an error rather than replay an unrelated response.

Per RFC 9110 and the IANA HTTP Method Registry, which of the following HTTP methods is idempotent but NOT safe?#

Options

Show answer

PUT is the HTTP method that is idempotent but not safe among GET, POST, PATCH and PUT. Repeating an identical PUT leaves the target resource in the same state, but PUT is not safe because it modifies the representation of the target resource on the server.

Why:

Per RFC 9110, a safe method is one whose semantics are read-only, and safe methods are also idempotent, so GET is both safe and idempotent and fails the 'not safe' condition. POST is neither safe nor idempotent. PATCH (RFC 5789) is listed in the IANA HTTP Method Registry as not idempotent, because applying the same patch document to different resource states can yield different results. PUT is idempotent, since repeated identical PUT requests leave the resource in the same state, but it is not safe because it changes the state of the target resource. The question is limited to the listed choices, so DELETE, which shares the same idempotent-but-not-safe property, does not appear.

Your REST API exposes a POST /charges endpoint for processing payments. A client sends a request with an Idempotency-Key: 8f14e45f header, but the connection drops before the response arrives. The client retries the identical request with the same Idempotency-Key: 8f14e45f header. In 2-3 sentences, describe what the server must do to ensure the charge is created only once and the client receives a consistent response.#

Show answer

The server must store the Idempotency-Key along with the request details and the resulting response (status code, headers, body) the first time it processes the charge. When the retry arrives with the same Idempotency-Key, the server returns the stored response instead of processing the charge again, so the payment is created exactly once and the client sees the same result both times.

Why:

Idempotency keys work by having the server persist a mapping from the key to the full response of the first request. On a retry with the same key, the server short-circuits processing and returns the stored response, which guarantees the side effect (charge creation) happens exactly once. This pattern matters for non-idempotent methods like POST, where a naive retry would create a duplicate charge.

An API requires an Idempotency-Key header on POST /payments. A client sends a charge, the server commits it successfully, but the 200 response is lost to a network timeout. The client retries with the same Idempotency-Key. What should a correctly-implemented server do?#

Options

Show answer

The server should recognise the stored key and return the exact same response it produced the first time, without charging the card again. An idempotency key makes an unsafe POST safe to retry: the server records the key alongside its response, then replays that stored response verbatim on any later request bearing the same key. So the timed-out retry gets the original 200 and the card is charged once.

Why:

The whole point of an idempotency key is to make an unsafe operation (POST of a charge) safe to retry: the server records the key together with the response it produced, and a later request bearing the same key replays that stored response verbatim instead of re-executing the side effect. So the timed-out retry gets the original 200 and the card is charged once. The option that describes plain stateless HTTP defeats the mechanism — it would double-charge. The option that says a repeated key is a malformed, duplicate request is wrong because a repeated key is exactly the expected, supported case, not a client error. The option that says to respond 409 Conflict is the tempting trap: 409 Conflict is the right answer only for the different scenario where a second request with the same key arrives while the first is still in flight — the server locks on the key and rejects the concurrent duplicate. For a replay of an already-completed request there is nothing in conflict; the server simply returns the cached original result.

Which HTTP methods are idempotent — making the identical request many times leaves the server in the same state as making it once?#

Options

Pick every one that applies.

Show answer

GET, PUT, and DELETE are idempotent — but not POST. Repeating PUT re-sets the same state, and repeating DELETE leaves the resource deleted (later calls may return 404, but the server state is unchanged). POST is not idempotent because each call typically creates a new resource, which is why retries need an idempotency key.

Why:

GET, PUT, and DELETE are idempotent: repeating PUT re-sets the same state, and repeating DELETE leaves the resource deleted (the later calls may return 404, but the server state is unchanged). POST is not idempotent — each call typically creates a new resource, which is why retries need an idempotency key (RFC 9110 §9.2.2).

This Express handler implements idempotent payments: clients send an Idempotency-Key and a retry with the same key should never charge twice. Under load, some customers are still being charged twice by simultaneous retries. What is the flaw?#

app.post("/payments", async (req, res) => {
  const key = req.header("Idempotency-Key");
  const existing = await store.get(key);
  if (existing) {
    return res.status(existing.status).json(existing.body);
  }

  const charge = await gateway.charge(req.body);
  const response = { status: 201, body: charge };
  await store.set(key, response);
  return res.status(response.status).json(response.body);
});

Options

Show answer

The key is only written to the store after gateway.charge returns, and the check-then-charge-then-store sequence is not atomic, so two concurrent retries both pass the existing check and both charge

Why:

The guarantee breaks because the key is recorded only after the side effect. The read (store.get), the charge, and the write (store.set) are three separate awaits with no lock and no atomic reserve. Two retries that arrive close together both run store.get before either has called store.set, both see no existing record, and both call gateway.charge — a double charge. The fix is to atomically reserve the key before charging (e.g. an INSERT … ON CONFLICT DO NOTHING / conditional put that the second request loses, or a row lock on the key), so a concurrent duplicate is detected up front and either waits for or replays the first result. The claim that the handler must use PUT is wrong: HTTP method semantics describe intent, they do not enforce at-most-once execution — PUT would have the identical race. The claim that replaying a stored response must use 200 OK is wrong: replaying the original response means returning the original status, including 201; rewriting it to 200 would misreport what happened. The claim that the server should generate the key itself is an actively harmful trap: the key must be minted by the client and held stable across attempts — that stability is what links a retry to its original. A server-generated key would differ on every attempt, so no two retries would ever match and deduplication would be impossible.

What does it mean for an HTTP method to be idempotent, and why does it matter for clients that retry?#

Show answer

An idempotent method produces the same server state whether the identical request is sent once or many times. PUT and DELETE are idempotent (and GET is too); POST is not. It matters because a client that times out can safely retry an idempotent request without risk of duplicating the effect — repeating a DELETE still leaves the resource gone, whereas blindly retrying a POST could create duplicates, which is why non-idempotent writes use an idempotency key.

Why:

Idempotency is about the effect on server state, not the response body: repeating an idempotent request leaves the same state as a single call (RFC 9110 §9.2.2). Safe methods are a subset — all safe methods are idempotent. This property is what makes automatic retries of GET/PUT/DELETE safe, while POST retries need an idempotency key to avoid duplicate side effects.

A REST API exposes PUT /users/{id}/profile. The client's request body contains only the profile fields (name, email, bio) and never contains update_count. The handler overwrites the stored profile with the request body, then sets the update_count field inside the same stored resource to its previous value plus 1. GET /users/{id}/profile returns update_count as part of the resource. Treat every change to the resource's observable state, including update_count, as an effect of the request, not as an out-of-band side effect such as logging. Using the RFC 9110 §9.2.2 definition (compare the intended effect of one request with the effect of multiple identical requests), state whether this endpoint is idempotent and justify your answer.#

Show answer

Not idempotent. Under RFC 9110 §9.2.2, a method is idempotent when the effect on the server of multiple identical requests equals the effect of a single one. Here the request body is identical each time, but update_count is part of the resource that GET returns, so after one PUT it is N and after two identical PUTs it is N+1. The resource state therefore differs between one request and repeated requests. The PUT method's idempotency is a contract the handler must honor; because this handler changes observable resource state on each repetition, it breaks that contract for this endpoint.

Why:

The question stipulates that the client never sends update_count, that the server increments it on every call, and that it is returned as part of the resource by GET. So a single PUT leaves the stored resource at update_count = N, while two identical PUTs leave it at N+1. Because the observable resource state differs between one request and repeated identical requests, the endpoint fails the RFC 9110 §9.2.2 comparison. The stipulation that this change counts as a request effect, not a permitted out-of-band side effect like logging, is what makes the answer decisive. The method name does not decide the question: PUT's defined idempotency is a contract the handler has to satisfy, and this handler does not.

The Python code below implements idempotency-key handling for a POST /payments endpoint. The table is defined as CREATE TABLE idempotency_keys (key TEXT), with no UNIQUE or PRIMARY KEY constraint, and db runs in autocommit mode, so each execute call commits immediately.#

Show answer

A TOCTOU (time-of-check-to-time-of-use) race condition between the SELECT that checks whether the idempotency key already exists and the INSERT that records it. Two concurrent requests with the same key can both run the SELECT before either INSERT commits, both see no row, both INSERT, and both call the payment gateway, causing a duplicate charge.

Why:

The code runs a SELECT to check whether the idempotency key exists, then, if no row is found, runs an INSERT to record the key, and only then calls the payment gateway. Because the table has no UNIQUE constraint and there is no transaction or lock around the two statements, nothing prevents two concurrent requests with the same key from both executing the SELECT before either INSERT has run. Both then see no row, both INSERT, and both charge, so the flaw is a TOCTOU race between the SELECT check and the INSERT write. A fix would be a UNIQUE constraint on the key column, with the INSERT's integrity error treated as 'already processed' (or an atomic INSERT ... ON CONFLICT), so the database rather than the application decides which request proceeds.

Per RFC 9110 (HTTP Semantics), define a safe method and an idempotent method, then classify GET, HEAD, OPTIONS, TRACE, PUT, DELETE, and POST as safe, idempotent, both, or neither. Finally, state what RFC 5789 (PATCH) says about PATCH's idempotency, and why it cannot be classified from the method name alone.#

Show answer

A safe method is one whose defined semantics are essentially read-only, so clients do not request state changes and may treat it as non-mutating. An idempotent method is one where the intended effect on the server of making the same request several times is the same as making it once. Per RFC 9110, GET, HEAD, OPTIONS, and TRACE are safe, and therefore also idempotent. PUT and DELETE are idempotent but not safe, since they modify state while repeating the same request leaves the same final state. POST is neither safe nor idempotent, because each request may create a new resource or trigger a unique side effect. RFC 5789 defines PATCH as a partial modification and does not guarantee idempotency for it; a PATCH whose patch document sets a field can be idempotent, while one that increments a counter is not, so idempotency depends on the patch format and can be enforced with conditional requests.

Why:

RFC 9110 defines a safe method by its essentially read-only semantics, so GET, HEAD, OPTIONS, and TRACE are safe; this is a statement about the method's defined semantics, not a guarantee that the server records nothing. Idempotency is defined by the intended effect on the server of repeating a request being the same as sending it once, so GET, HEAD, OPTIONS, TRACE, PUT, and DELETE are idempotent. Safe methods are therefore also idempotent. PUT and DELETE modify state but are idempotent because repeating them leaves the same final state. POST is neither because repeated requests may create separate resources or trigger separate side effects. RFC 5789 does not guarantee PATCH idempotency: a patch that sets a field can be idempotent, while one that increments a counter is not, so PATCH cannot be classified from the method name alone.

An e-commerce REST API exposes POST /orders to create a new order. The server assigns the order ID, so the client cannot use PUT /orders/{id}. The API team wants to guard against duplicate orders when a client retries after a network timeout. Describe the standard Idempotency-Key pattern for making this POST endpoint safe against duplicate submissions: what the client sends, what the server stores, and what the server returns on a retried request whose original request already succeeded. What HTTP status code should the replayed response carry?#

Show answer

The client generates a unique Idempotency-Key (for example, a UUID) and sends it as a request header on every attempt of the POST /orders call, reusing the same key when it retries. The server stores the key together with a fingerprint of the request parameters and the full response it produced (status code, headers, body). When a request arrives with a key that already has a stored result, the server returns that stored response verbatim without re-processing the request or creating a second order. If no result exists for the key, the server processes the request normally and persists the result under that key. The replayed response carries 201 Created, the same status the original successful creation returned, because the server replays the exact stored response rather than computing a new one.

Why:

The Idempotency-Key pattern is a server-side convention layered on top of the non-idempotent POST method, since HTTP itself does not define this header. The client generates a unique key and reuses it on retries. The server persists the key with the request and the complete response it produced, and on a repeated key it replays that stored response, including the original status. For an order that was successfully created, the replay therefore carries 201 Created, not 200 OK, because the stored response is returned verbatim and no new operation is executed.

A REST API uses PUT /widgets/{id} to replace the entire representation of a widget resource. A client sends PUT /widgets/7 with body {'name':'gadget','version':1}, and the resource does not yet exist. The server creates it and returns 201 Created with body {'name':'gadget','version':1,'created_at':'2024-06-01T10:00:00Z'}. The client hits a network timeout and retries the identical request. The server now returns 200 OK with the same body and the same created_at value, and no state change occurs. A teammate argues that because the status changed from 201 to 200, the PUT is not idempotent and the API should use POST instead. Which statement is correct?#

Options

Show answer

The status change does not make PUT non-idempotent. HTTP idempotency (RFC 9110 §9.2) is judged by the intended effect on server state, not by response equality. A retried identical PUT leaves the resource unchanged, and the 201 to 200 difference simply reflects that the resource already exists. POST is not idempotent by definition, so switching would not help.

Why:

Per RFC 9110 section 9.2, idempotency is defined by the intended effect on server state: making the same request N times should leave the server in the same state as making it once. It places no requirement that responses match. The first PUT creates the resource, so 201 Created is correct (RFC 9110 allows PUT to return 201 when it creates a resource). The retry finds the resource already in the target representation, so the server answers 200 OK and changes nothing, which is exactly what idempotency requires. The status difference reflects the server's knowledge of the prior creation, not a second state transition. POST is not idempotent by definition, so moving to POST would make the non-idempotency real rather than fix it.

RFC 9110 (HTTP Semantics) defines idempotency for certain HTTP methods. Which of the following statements is true about idempotency as defined in that specification?#

Options

Show answer

Logging each request does not violate idempotency. RFC 9110 §9.2.2 defines idempotency by the intended effect of the requested action on server state, so the server may separately perform independent actions such as writing log entries or incrementing a request counter. Idempotent methods need not be safe, and POST is not idempotent.

Why:

Per RFC 9110 §9.2.2, a request method is idempotent when multiple identical requests with that method have the same intended effect on server state as a single such request. The specification explicitly says the idempotent property applies only to what the user requested, and the server may separately initiate actions independent of the request, such as logging, without violating idempotency. The statement about logging and counters is therefore the true one. The statement that idempotent methods must be safe is false, since PUT and DELETE are idempotent but not safe. POST is not defined as idempotent, and the specification does not require identical response bodies across repeated requests.

A REST API implements these endpoints (RFC 9110 semantics assumed throughout):<br><br>• <code>GET /widgets/{id}</code> — returns the widget or 404.<br>• <code>PUT /widgets/{id}</code> — creates or replaces the widget with the request body; returns 201 on first create, 200 on subsequent replace.<br>• <code>DELETE /widgets/{id}</code> — deletes the widget; returns 200 if it existed, 404 if not.<br>• <code>POST /widgets/{id}/views</code> — increments a view counter; returns 200.<br>• <code>POST /widgets</code> — creates a new widget with a server-generated id; returns 201.<br><br>Regarding HTTP idempotency as defined by RFC 9110, which of the following statements are TRUE?#

Options

Pick every one that applies.

Show answer

Three statements hold: DELETE and PUT are idempotent because RFC 9110 defines idempotency as identical server state after one or more identical requests — not identical responses — so different status codes (200→404, 201→200) conform. POST …/views is non-idempotent since the counter changes per call. The other two fail: GET safety doesn't bar all server side effects (the RFC acknowledges logging), and POST has no protocol-level deduplication requirement on retry.

Why:

RFC 9110 defines idempotency as a property of server state — identical requests, whether issued once or N times, leave the server in the same state — not as identical responses. DELETE and PUT are idempotent methods: after two identical DELETE calls the resource is gone just as it was after the first, and after two identical PUT calls with the same body the resource content is the same as after one. The differing status codes (200→404 for DELETE, 201→200 for PUT) are fully conformant because the RFC states that idempotent requests 'might not have the same response.' POST /widgets/{id}/views is non-idempotent: each call mutates the counter, so the server state after two calls differs from after one. The GET statement is false because the RFC explicitly acknowledges that 'it is not possible to ensure that the server does not generate side effects while handling a request' — safety concerns the requested semantics (read-only intent), not a prohibition on all server-side side effects. The POST /widgets statement is false because POST is not idempotent per the spec; there is no protocol-level requirement to deduplicate or return the same resource id on retry — preventing duplicates is an application-level concern typically handled with an Idempotency-Key header or a uniqueness constraint.

A REST API for an order management system exposes these endpoints:#

Options

Pick every one that applies.

Show answer

The correct statements are that PUT is idempotent under RFC 7231, that DELETE is idempotent because repeated deletes leave the resource absent, and that a POST with an Idempotency-Key returns the stored original response for duplicates. PATCH is not idempotent by its method definition, and a JSON Patch add to /tags/- appends a new element on every application.

Why:

The three correct statements are the PUT claim, the DELETE claim, and the POST-with-Idempotency-Key claim. RFC 7231 section 4.2.2 defines PUT as idempotent because the intended effect of a full replacement is the same whether it is sent once or many times, and it names DELETE as idempotent because repeating a delete leaves the resource absent; a second DELETE returning 404 does not change server state. The Idempotency-Key convention makes a retried POST safe by returning the stored original response instead of re-running the operation. The PATCH claim is wrong because RFC 5789 explicitly says PATCH is not required to be idempotent; a particular patch document may happen to be idempotent, but that is a property of the document, not a method-level guarantee. The JSON Patch claim is wrong because an add to /tags/- appends on every application, so applying it once yields ['vip'] and applying it twice yields ['vip','vip'], which differ.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See http-apis salaries and hiring demand from live job postings.

Practise these until they stick

That's every question we hold on this topic, and the page marks what you pick. What it can't do is remember. A free account keeps every answer, and what you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.