I have difficuties understanding REST principled for updating resource.
For example this response contains id of a resource
GET /users/5 { "user_id": 5 "first_name" : "John", "last_name" : "Doe", "minutes_active": 10
} And this assumes that an id of a resource is one stated in the url of a request
GET /users/5
{
"first_name" : "John",
"last_name" : "Doe",
"address":
{
"street" : "First Street 10",
"postal" : "0000",
"city": "Dublin"
},
"phones": [
{
"type" : "work",
"number" : "555 473-0000",
},
{
"type" : "home",
"number" : "555 473-0000",
}]
}
If i want to update only address I am thinking of using one of the following options.
1.
POST /users/5
{
"address":
{
"street" : "First Street 10",
"postal" : "0000",
"city": "Dublin"
}
}
2.
PUT /users/5
{
"address":
{
"street" : "First Street 10",
"postal" : "0000",
"city": "Dublin"
}
}
3.
PUT /users/5/address
{
"address":
{
"street" : "First Street 10",
"postal" : "0000",
"city": "Dublin"
}
}
Although POST is not idempotent it will always do the same work in this case (act as idempotent), as well as PUT. I somewhere read that this type of request is considered a partial update, and for this types of request we should use PATCH.
At this point I would like to avoid PATCH, and use some alternative.
Furthermore, if I isolate address as a separate resource in /users/5/address i could use PUT and it would be a solution that fully follows REST principles. But this could be a problem I a developer want to update fe. both phones and addresses using a single request.
If I would really want to use options 1 or 2 (and some huge systems such as zendesk, twitter are doing so), could I encounter any serious issues that I dont really see at this point?