PUT method

The HTTP PUT method replaces a document fragment or creates a new document. When combined with a selector range unit, it replaces the matched element with the request body.

When to reach for it

Use PUT to overwrite an existing element or to store a new document at a given path. The server returns 206 Partial Content with a Content-Range header identifying the replaced element.

All PUT requests are subject to authorization.

Examples

Replace a single element

Given a document with a heading and a paragraph, replace the heading:

PUT /put-replace-test.html
Range: selector=h1
Content-Type: text/html

<h1>New Header</h1>
HTTP/1.1 206

<h1>New Header</h1>

Write persists

After replacing a heading, the change is stored:

PUT /put-persist-test.html
Range: selector=h1
Content-Type: text/html

<h1>Updated Title</h1>
HTTP/1.1 206

<h1>Updated Title</h1>

Reading the document back confirms the update:

GET /put-persist-test.html
Range: selector=h1
HTTP/1.1 206

<h1>Updated Title</h1>

What the response contains

A selector-scoped PUT with an HTML body answers with the replacement markup, without any whitespace before or after it. So if your request body ends in a newline, the response does not. The ETag describes exactly that body: hash the body with SHA-256 and you get the first part of the ETag. A later read of the element returns the same ETag. The stored document keeps the whitespace you sent.

2 cases are different:

The response has no ETag at all in these cases:

Editing a large page

On a page of 256 KiB or more, a PUT addressed by #id, by .class, or by an exact attribute value, such as [data-key="7"], can read only the element it replaces, not the whole page, so its cost does not grow with the page. When anything else needs the whole page, such as a schema rule on the element or a replacement the server cannot settle from the element alone, the edit reads the whole page as before. The response is the same as on any page. The page's own ETag is not worked out by the edit: the live-update event it sends names none, and the next GET of the page returns the new one.

Concurrency

To protect a whole-document PUT against lost updates, send the ETag you last read in an If-Match header. The write only succeeds if the document is still at that version when the write commits — if another client's save lands first, even a moment before yours, your PUT is rejected with 412 Precondition Failed instead of silently overwriting their work. The 412 response carries the document's current ETag, so you can re-read and retry without an extra GET.

If-Match accepts the standard HTTP forms:

The same protection works element by element: a selector-scoped PUT with If-Match is checked against the ETag a selector read of that element hands out. That includes an element that arrives on a page by stamping or inclusion from another document. Reading such an element through the composed page gives you the validator of its origin document — the document your write actually lands in — so you can read, then write back conditionally, all through the composed page.

An element's ETag names both what you were shown and what is stored. Only the stored half decides a conditional write, so a page that changes an element's markup on the way out to you does not stop you saving it back. A schema read resolver is the common case: it can rewrite a property value on every read, and you can still write back with the ETag you were given, on a plain page and through a composed page alike.

Two different things can go wrong with a selector-scoped If-Match, and the 412 tells you which:

The second case is what you get if you send a neighbouring element's ETag, or an ETag you read from a different document. It also happens when composition itself changed the element's markup, rather than a read resolver: composition removes every namespace-prefixed attribute whose prefix the page declares with xmlns:, which on a normal page means all of the p: and e: attributes, so an element carrying any of them is served without them. An element that holds a transient element splices in content for your session. In both of those cases the server does not know what is stored behind what it composed, so it refuses. To save your change, write to the document the element is stored in, or edit it over WebDAV.

A write to a transient element is different: it changes your session's copy, not the document, and its If-Match is checked against your session's copy. Save with the ETag your last read or save of it gave you. See Transient Elements.

An element with no prefixed attributes and no transient content is served as it is stored, and a conditional write through the composed page works.

The mirror header If-None-Match blocks a write when a listed ETag (or *, meaning "if it exists at all") matches the current version — use If-None-Match: * for create-only semantics: the PUT succeeds only when the path is not yet taken.

Error cases

Condition Status
Document does not exist 404 Not Found
Selector matches no element 416 Range Not Satisfiable
Authorization denied 403 Forbidden
A Range header with more than one selector= 400 Bad Request
Target path is under the reserved /.pagelove/ namespace 403 Forbidden
Schema validation fails 422 Unprocessable Entity
Body exceeds the request-body size cap 413 Content Too Large
Write kept losing to concurrent writers of the same document for the whole retry window 409 Conflict
Host has transition rules and the page changed while the write was being checked 409 Conflict
Supplied supported If-Match or If-None-Match precondition is not satisfied 412 Precondition Failed
A whole-page save ran longer than its 5 minute limit; nothing is stored, so you can send it again 504 Gateway Timeout
Host has transition rules and a file that is not HTML would replace a page holding a watched item with no declared exit 422 Unprocessable Entity

An unconditional whole-document PUT can retry internally under contention. It uses last-writer-wins replacement semantics: replaying an old payload can replace content that changed since the client prepared it. Sustained contention can exhaust a bounded retry window and return 409 Conflict with a WriteContention error. Inspect the actual error; a 409 alone is not a universal assurance that repeating the request is appropriate.

On a host with transition rules, every PUT the rules check is pinned to the version of the page the server read, whether or not it touches a watched item. If the page changed in between, the PUT gets the same 409 Conflict instead of overwriting the change. This applies to selector-scoped PUTs too, which are not re-applied on such a host. A deliberate new attempt is checked against the current page and can now fail validation; review the change rather than assuming the same request remains appropriate. An If-Match with a specific ETag, or an If-None-Match: *, that no longer holds still gets 412. An If-Match: * names no version, so it gets the 409 like a PUT with no condition. See TransitionConstraint for the writes the rules do not check.

After an observed refusal, keep the frozen pending change and any newer draft edits. Read the actual target with the appropriate authorization and representation, review its current content and validator, and reconcile before deliberately submitting again. Keep the supported precondition for the intended write; do not silently remove it or automatically resend a stale whole-document replacement. The save-state model explains the draft, pending and confirmed boundaries.

A timeout or lost response leaves acceptance Unknown, rather than establishing a refusal. Retain the pending change and investigate before repeating a write that could overwrite or duplicate work; matching current content alone does not identify which request committed it. Review configured automation and independent effects separately before retrying. The main PUT outcome is not a universal rollback or exactly-once guarantee for those effects.

A PUT of a file that is not HTML, sent to a path that holds a web page, counts as deleting that page when the host has transition rules. It is refused with 422 if the page holds a watched item and the rules declare no exit for it. See Transition constraints.

Where an element deny applies to you, a whole-page PUT is also compared with the page as the database stores it, and you get 412 if the page changed between that check and your save, even when you sent no If-Match. See an element deny also guards a whole-page write.

A PUT with a selector never saves a file. It edits one element, whatever its Content-Type and whatever the path. This holds for a page stored at a path with no extension too, so a text/plain PUT with a selector changes the text of that element and keeps the rest of the page.

Absence and denial are distinct. A selector that matches no element gets 416, and one you are not permitted to write gets 401/403 — the two are never confused. Where the edge cannot see your target it re-checks against the live document before answering, so a 416 means the element really was absent at that moment. Two cases still refuse rather than reporting 416: a target that exists but is covered by a rule denying it, which is a genuine authorization answer rather than an absence; and a target you would not be permitted to read, since "there is nothing there" is itself information about the page. If you can write to part of a page you cannot read, writes refuse identically whether the target exists or not.

Reserved namespace. The /.pagelove/ path prefix is reserved for the platform's internal documents and is not writable. Any write (PUT, POST, DELETE, MOVE) targeting a path under /.pagelove/ is refused with 403 Forbidden; choose a different path for your own documents.

Request body size limit

Every write request's body is subject to an operator-configured size cap (1 GiB unless changed; it can also be tuned per site, so the limit may differ between hosts). A request whose Content-Length exceeds the cap is answered 413 Content Too Large immediately, without the body being read; an upload without an accurate Content-Length (for example, chunked) is rejected with 413 as soon as it exceeds the cap. The 413 response body is HTML carrying https://pagelove.org/Error Microdata with status and message properties, and the connection is closed.

Send an accurate Content-Length when uploading large content so an over-limit request fails fast instead of transferring the whole body.

See also