use POST for operations whose noun doesn't denote the same resource that a GET would denote, or that have side effects #324
Labels
No Label
0.2.0
0.3.0
0.4.0
0.5.0
0.5.1
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
1.0.0
1.1.0
1.10.0
1.10.1
1.10.2
1.10a2
1.11.0
1.12.0
1.12.1
1.13.0
1.14.0
1.15.0
1.15.1
1.2.0
1.3.0
1.4.1
1.5.0
1.6.0
1.6.1
1.7.0
1.7.1
1.7β
1.8.0
1.8.1
1.8.2
1.8.3
1.8β
1.9.0
1.9.0-s3branch
1.9.0a1
1.9.0a2
1.9.0b1
1.9.1
1.9.2
1.9.2a1
LeastAuthority.com automation
blocker
cannot reproduce
cloud-branch
code
code-dirnodes
code-encoding
code-frontend
code-frontend-cli
code-frontend-ftp-sftp
code-frontend-magic-folder
code-frontend-web
code-mutable
code-network
code-nodeadmin
code-peerselection
code-storage
contrib
critical
defect
dev-infrastructure
documentation
duplicate
enhancement
fixed
invalid
major
minor
n/a
normal
operational
packaging
somebody else's problem
supercritical
task
trivial
unknown
was already fixed
website
wontfix
worksforme
No Milestone
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Reference: tahoe-lafs/trac-2024-07-25#324
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
kpreid pointed out that using
PUT <http://localhost:8123/uri>
to PUT a file is wrong becauseGET
on that same URL won't return that same file. We should usePOST
for things whose noun doesn't denote their resource, namely operations which don't also link the thing into a directory, i.e.:For creating a directory, source:docs/frontends/webapi.txt#L343 says that 'The "PUT" operation is provided for backwards compatibility: new code should use POST.' There isn't any similar wording for files, though. Is this just a documentation bug, or is there code that needs to change?
I haven't thought through it carefully. PUT seems like a good verb for uploading a file, but certainly "PUT /uri" doesn't correspond to "GET /uri" (since "GET /uri" isn't even legal). "PUT /uri/DIRCAP/filename" would match "GET /uri/DIRCAP/filename", so I think that's ok.
My understanding of REST is that POST is for side-effecty things (and is frequently used to effectively send a message to the resource named by the URL), PUT is for creating new resources in a specific place, and GET is for retrieving those resources from that specific place. Uploading new files is side-effecty and creates a new resource, but not in a specific place. So I guess "POST /uri" is probably a reasonable immutable-upload operation, and we should stop using "PUT /uri".
As of 1.6.1 there is already an existing
POST /uri
handler. For the case of files it requires at=upload
parameter and the response is suitable for browsers (either html or an HTTP redirection).Tangentially there appears to be a convention where some
POST
operations accept anoutput=json
parameter.So, davidsarah and nejucomo propose adding a handler for
POST /uri?output=json
. This should be backwards compatible to existing clients, but solves the issue raised in this ticket.This ticket raises a design consistency issue, but I want to point out a practical issue:
As of 1.6.1 it's not easy to use python
urllib2
to publish an unlinked file or directory. It cannot doPUT
out-of-the-box (maybe possible by creating custom request handlers). Meanwhile the only output options forPOST /uri?t=upload
are html or an HTTP redirect.urllib2
transparently follows redirects, so this leaves html scraping or custom urllib2 request handlers as the alternatives.Now that that is clearer it might be time to switch to httplib.
For consistency with the existing
POST /uri?...
code ([here]source:src/allmydata/web/root.py?rev=4238#L64), bothPOST /uri?output=json
andPOST /uri?t=upload&output=json
would be allowed with the same meaning.The specification for this operation needs to say what the output JSON looks like. I would suggest it should be exactly like the output of
GET $FILECAP?t=json
for the resulting file.Slightly off-topic for this ticket, but switching to httplib for the CLI commands would also make it easier to fix #965, IIUC.
Replying to davidsarah:
Oh, I'm not making sense. The CLI commands already use
httplib
; it is changing them to useurllib2
that would make #965 easier (and that is definitely off-topic here).Similar to #1428, but not quite the same issue.(#1428 is invalid.)
use POST for operations whose noun doesn't denote the same resource that a GET would denoteto use POST for operations whose noun doesn't denote the same resource that a GET would denote, or that have side effects