3 ms·
Use PUT [0], GET, and DELETE to upload/download/delete binary blobs at the same URL. A successful PUT response is "201 Created" [1] with a "Location" header wi
by mleonhard 5y ago
Use PUT [0], GET, and DELETE to upload/download/delete binary blobs at the same URL. A successful PUT response is "201 Created" [1] with a "Location" header with the final URL of the blob. PUT is also idempotent.
I've never seen PATCH [2] used effectively. I would expect a PATCH request body to be a diff of an existing file which is retrievable with GET. Optimizations are not worthwhile for most projects.
Most APIs do not store binary blobs. Most APIs operate on complicated sets of database tables and should use POST, GET, and maybe DELETE.
[0] https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PU...
[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PA...
- ojhughes 5y agoThe Kubernetes API implements patch correctly FWIW. Patching objects in k8s is advisable where possible instead of replacing as it allows the control plane to gracefully update the resources (without downtime). https://blog.atomist.com/kubernetes-apply-replace-patch/ https://blog.atomist.com/kubernetes-apply-replace-patch/
- mleonhard 5y agoI found nothing in the docs [0, 1] about downtime due to Replace or Patch. Both commands change the spec. Downtime from a spec change seems to be unrelated to the manner of changing the spec. The standard way to implement optimistic concurrency with HTTP REST APIs is using the If-Match header [2]. The Kubernetes authors chose to use a 'resourceVersion' query parameter instead [0]. Kubernetes Team decided to implement *three* different kinds of patches: JSON patch, JSON merge patch, and strategic merge patch. Kubernetes Team also chose to put 1,500 pages of docs on a single page, making searching extremely difficult or impossible. Bazel team [3] and Flutter team [4] also make their docs difficult to search. Kubernete's Patch implementation may be technically correct, but it has a lot of usability problems, which translate into wasted engineering effort maintaining integrations with it. [0] https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#resource-operations-update https://kubernetes.io/docs/reference/generated/kubernetes-ap... [1] https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/ https://kubernetes.io/docs/tasks/manage-kubernetes-objects/u... [2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If... [3] https://docs.bazel.build/versions/main/command-line-reference.html https://docs.bazel.build/versions/main/command-line-referenc... [4] https://github.com/flutter/flutter/issues/80849 https://github.com/flutter/flutter/issues/80849
- zozbot234 5y ago> Most APIs do not store binary blobs. Most APIs operate on complicated sets of database tables SPARQL can be used to PATCH/PUT database entries in a standardized and REST-friendly way.