Skip to content

Instantly share code, notes, and snippets.

@simonrenoult

simonrenoult/http-patch.md

Last active Nov 12, 2018
Embed
What would you like to do?
Exemple d'un requête PATCH non-idempotente

Etant donné la ressource :

GET /articles/1234 HTTP/1.1

HTTP/1.1 200 OK
{ "title": "PUT vs PATCH","tags": ["http", "api", "rest"] }

Si j'exécute plusieurs fois la requête PATCH d'ajout d'un tag via le format JSON Patch (sans l'utilisation d'un etag)

PATCH /articles/1234 HTTP/1.1
Content-Type: application/json-patch+json

[{ "op": "add", "path": "/tags", "value": ["put"] }]

Alors j'aboutis successivement à plusieurs représentations de la ressource :

GET /articles/1234 HTTP/1.1

HTTP/1.1 200 OK
{ "title": "PUT vs PATCH","tags": ["http", "api", "rest", "put" ] }
GET /articles/1234 HTTP/1.1

HTTP/1.1 200 OK
{ "title": "PUT vs PATCH","tags": ["http", "api", "rest", "put", "put"] }
GET /articles/1234 HTTP/1.1

HTTP/1.1 200 OK
{ "title": "PUT vs PATCH","tags": ["http", "api", "rest", "put", "put", "put"] }

Donc cette requête (en l'absence d'etag tout du moins) n'est pas idempotent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment