Skip to content

Glossary idempotent #40369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 16, 2025
Merged

Glossary idempotent #40369

merged 10 commits into from
Jul 16, 2025

Conversation

mb21
Copy link
Contributor

@mb21 mb21 commented Jul 15, 2025

Description

Clarify PATCH idempotency in body text

Motivation

Previously the paragraph mentioned PUT, DELETE and POST but curiously left out PATCH, which on a cursory reading could be interpreted as PATCH being idempotent (yes, the cursory reader was me).

@mb21 mb21 requested a review from a team as a code owner July 15, 2025 08:38
@mb21 mb21 requested review from chrisdavidmills and removed request for a team July 15, 2025 08:38
@github-actions github-actions bot added Content:Glossary Glossary entries size/xs [PR only] 0-5 LoC changed labels Jul 15, 2025
Copy link
Contributor

github-actions bot commented Jul 15, 2025

Preview URLs

(comment last updated: 2025-07-16 08:13:34)

Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mb21, and thanks for the contribution!

I'm not an expert on this, but from what I've read on the subject, your addition seems like an oversimplification. PATCH can be idempotent or non-idempotent, depending on how your request is written to update the data you are modifying.

This thread contains some good examples: https://softwareengineering.stackexchange.com/questions/260818/why-patch-method-is-not-idempotent

Perhaps it'd be a good idea to include PATCH in a separate paragraph, along the lines of "{{HTTPMethod("PATCH")}} is a special case...",

@mb21
Copy link
Contributor Author

mb21 commented Jul 15, 2025

From your link:

A PATCH request can be idempotent, but it isn't required to be. That is the reason it is characterized as non-idempotent.

That's exactly right. And it's exactly the same for POST. Perhaps the whole article should be clarified then? I can take a stab at it.

@chrisdavidmills
Copy link
Contributor

From your link:

A PATCH request can be idempotent, but it isn't required to be. That is the reason it is characterized as non-idempotent.

That's exactly right. And it's exactly the same for POST. Perhaps the whole article should be clarified then? I can take a stab at it.

Yeah, I think it might be a good idea. I read the "That is the reason it is characterized as non-idempotent" line and thought, "well, that sounds a bit hand-wavy and vague".

@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Jul 15, 2025
@mb21
Copy link
Contributor Author

mb21 commented Jul 15, 2025

Updated! Let me know whether its clearer now. btw. actually the linked spec is quite well-written: https://httpwg.org/specs/rfc9110.html#idempotent.methods

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks @mb21! I've included a few wording suggestions, but I think this is pretty close now.


To be idempotent, only the state of the server is considered. The response returned by each request may differ: for example, the first call of a {{HTTPMethod("DELETE")}} will likely return a {{HTTPStatus("200")}}, while successive ones will likely return a {{HTTPStatus("404")}}. Another implication of {{HTTPMethod("DELETE")}} being idempotent is that developers should not implement RESTful APIs with a _delete last entry_ functionality using the `DELETE` method.
Idempotency, as defined by the HTTP specification, only considers the _intented_ effect of the client on the server: for example, a POST request intends to send data to the server, or a DELETE request intends to delete a resource on the server. A request with an idempotent method does not necessarily mean that the request does not have _any_ unique side effects: for example, the server may log every request with the time it was received.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Idempotency, as defined by the HTTP specification, only considers the _intented_ effect of the client on the server: for example, a POST request intends to send data to the server, or a DELETE request intends to delete a resource on the server. A request with an idempotent method does not necessarily mean that the request does not have _any_ unique side effects: for example, the server may log every request with the time it was received.
In the context of HTTP, idempotency only considers the _intended_ effect of the client on the server. For example, a POST request intends to send data to the server, whereas a DELETE request intends to delete a resource on the server. A request with an idempotent method does not necessarily mean that the request has _no_ unique side effects: For example, the server may log the time each request is received.

You mentioned something to the effect of "defined by HTTP specification" twice, so I reworded one to get rid of repetition.

Copy link
Contributor Author

@mb21 mb21 Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind the repetition, as it's kinda crucial to understand that we're only talking about the HTTP spec here.

I was actually looking into this for this chapter of a guide I'm writing: https://mastrojs.github.io/guide/http-forms-and-rest-apis/#client-side-fetching-a-rest-api and worded it there:

While the HTTP specification only talks about the effect on the server that the client intended, in practice it falls to the server to make sure the routes it exposes actually adhere to these semantics.

Not sure that's sufficiently clear? Because in practice, whether a request actually is idempotent or not (like whether actually it has the same effect whether it comes in multiple times or once) is entirely up to the server. But the HTTP spec didn't want to mandate that to servers, so it only talks about the effects the client intended. So they kinda say "btw FYI server: if a client sends you a GET, and since we're assuming the client adheres to the spec, then obviously the client intended an idempotent operation."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the repetition as a deal breaker.

I like the sentence you've provided here, but it is a bit different in form to the original you provided. Maybe we could combine the two, maybe something like:

Suggested change
Idempotency, as defined by the HTTP specification, only considers the _intented_ effect of the client on the server: for example, a POST request intends to send data to the server, or a DELETE request intends to delete a resource on the server. A request with an idempotent method does not necessarily mean that the request does not have _any_ unique side effects: for example, the server may log every request with the time it was received.
The HTTP specification only defines idempotency in terms of the _intented_ effect of the client on the server. For example, a `POST` request intends to send data to the server, whereas a `DELETE` request intends to delete a resource on the server. In practice, it falls to the server to make sure the routes it exposes adhere to these semantics. Also, a request with an idempotent method does not necessarily mean that the request has _no_ unique side effects: For example, the server may log the time each request is received.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I committed that suggestion, only to realize it's kinda the same point as the last paragraph?

While servers are very much encouraged to adhere to the semantics laid out by the HTTP specification, the spec does not mandate it. Nothing is preventing a server in the wild from exposing a non-idempotent endpoint under an idempotent HTTP method, although clients may well be surprised.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about that, but I don't think it is making exactly the same point.

The first instance is saying that it is down to the server to adhere to those semantics.

The second instance is a follow-on — it says that servers are encouraged to adhere to the semantics, but nothing is forcing them to.

Tell you what, I'll edit it and move things around a bit, to make this link clearer, then I'll ask you what you think of the result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mb21 OK, done. WDYT? I'm not sure how long it will take to propagate to the live preview, but you can view the changes immediately in the "Files changed" tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! I just added one minor clarification, then I think it's good to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, that looks good!

mb21 and others added 6 commits July 15, 2025 14:53
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
@mb21 mb21 changed the title Glossary idempotent: clarify PATCH Glossary idempotent Jul 16, 2025
Co-authored-by: Mauro Bieg <mb21@users.noreply.github.com>
Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we are ready to publish this one. Thanks so much for your work on this, @mb21 — this reads much better now.

@chrisdavidmills chrisdavidmills merged commit 12ec796 into mdn:main Jul 16, 2025
8 checks passed
@mb21 mb21 deleted the patch-2 branch July 16, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Glossary Glossary entries size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants