Last active
August 29, 2015 14:21
-
-
Save JacobASeverson/7b4e18d09cd50aa0c4a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) POST a new Event to the server | |
curl -i -X POST -H "Content-Type:application/json" \ | |
-d '{"name":"Basilica Block Party", "description":"Test description"}' \ | |
http://localhost:8080/events | |
# 2) Notice that an ETag header is populated with the contents of the version field | |
# (starting at 0) | |
HTTP/1.1 201 Created | |
Server: Apache-Coyote/1.1 | |
ETag: "0" | |
Last-Modified: ... | |
Location: http://localhost:8080/events/555557f6d4c6560c6f87f186 | |
# 3) Update the description of the event with a PATCH. The If-Match header matches | |
# the current resource ETag so this update will work. | |
curl --request PATCH -i -H "Content-Type:application/json" -H "If-Match:0" \ | |
-d '{"description":"Updated description"}' \ | |
http://localhost:8080/events/55555bc2d4c6f98f355b003e | |
# Update succeeds and the ETag is incremented | |
HTTP/1.1 200 OK | |
Server: Apache-Coyote/1.1 | |
ETag: "1" | |
Last-Modified: ... | |
# 4) Try another update, but use an out-of-date If-Match value of 0. This simulates the | |
# scenario where the resource was requested, but another client or user changed the | |
# resource before this PATCH could be applied. | |
curl --request PATCH -i -H "Content-Type:application/json" \ | |
-H "If-Match:0" \ | |
-d '{"description":"This update should NOT work"}' \ | |
http://localhost:8080/events/55555bc2d4c6f98f355b003e | |
# The server returns a 412 to notify you the resource changed before the PATCH | |
# and a fresh GET should be executed so you don't overwrite the changes of another client. | |
HTTP/1.1 412 Precondition Failed | |
# 5) At this point the ETag for this resource is "1", so update the If-Match to that. | |
curl --request PATCH -i -H "Content-Type:application/json" \ | |
-H "If-Match:1" \ | |
-d '{"description":"This update SHOULD work"}' \ | |
http://localhost:8080/events/55555c2d4c6f98f355b003e | |
# This update worked since the If-Match value matched the current ETag. It is incremented to 2. | |
HTTP/1.1 200 OK | |
Server: Apache-Coyote/1.1 | |
ETag: "2" | |
Last-Modified: ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment