Hi all.
I've read http related rfc's and realize the purpose and semantics of PUT method: create or replace resource specified by URI.
But one sentence in section 4.3.4 of RFC7231 bothers me as I'm not sure how properly interpret it and apply to real world api's building:
A successful PUT of a given
representation would suggest that a subsequent GET on that same
target resource will result in an equivalent representation being
sent in a 200 (OK) response
I'm confused about the mentioned response status and related representation: does it referes to PUT or GET response?
In case of it's related to PUT, then I think that this sentence states the following constraint of PUT behaviour
1.We make a PUT request that responses with 200 and body
PUT /uri
HTTP/1.1 200 OK
.....
${putResponseBody}
2. Then we make GET request that responses with 200 and body
GET /uri
HTTP/1.1 200 OK
......
${getResponseBody}
and the the following should be true:
${putResponseBody} == ${getResponseBody}
( of course in case of no concurrent modifucations are performed that managed to change resource representation between subsequent requests)
But this also means that it's valid to do PUT requests that holds only partial (read mutable state). Here is the example to clarify my idea:
1. We have a resource that contains a mix of immutable and mutable properties:
{
"id" : "123",//immutable, defined once at creation time
"dateCreated" : "2015-06-22T12:45:00", //immutable, defined at creation time
"orderList" : [
{"name" : "widget", "qty" : 1}
],
"deliveryDate" : "2015-06-28"
}
2. Then I can make a PUT and pass only mutable fields, that are valid to change:
PUT /orders/123
{
"orderList" : [
{"name" : "widget", "qty" : 1},
{"name" : "gadget", "qty" : 2}
],
"deliveryDate" : "2015-06-25"
}
if PUT returns representation with "filled immutables":
HTTP/1.1 200 OK
{
"id" : "123",//immutable, defined once at creation time
"dateCreated" : "2015-06-22T12:45:00", //immutable, defined at creation time
"orderList" : [
{"name" : "widget", "qty" : 1},
{"name" : "gadget", "qty" : 2}
],
"deliveryDate" : "2015-06-25"
}
thus returning to client a "complete" representation.
Of course if it's referred to GET, then the example above is not correct and then we come back to "well known" put description: if field is missing in PUT body then client intentionally missed it, even if it is immutable.
I'd appreciate any help with clarification of this spec part.
Thank you!
Dmitry