Suppose there is a primary resource "/accounts" which has Profile (name, national id, DOB), addresses and contacts(email, phones). I am considering them as sub-resources because they cannot exist without an account. To update them I am thinking two options
Option 1
- PUT /accounts/{accountid}/address
- PUT /accounts/{accountid}/contacts
- PUT /accounts/{accountid}/profile
Option 2
- PUT /accounts/{accountid}
(Depending on the presence/absence of address/phone/profile decide which updates to perform)
I am tempted to use option 1 because from implementation perspective each of the updates have own logic & process flow. A separate URI may keep implementation cleaner & manageable
- Would it be incorrect to consider profile,address,contacts as subresources. if so, what would be an appropriate way of representing them
- If they can be considered sub-resources which among the above is an appropriate option or is there a completely different option to be considered
PUT
is supposed to be an update-in-whole sort of action. At least in theory, you should be able toPUT
to a resource and then immediatelyGET
that same resource; theGET
should return exactly the same thing that you previouslyPUT
. In particular this suggests that aPUT
of a partial resource (eg updating only the address of an account) is not idiomatic. The spec is fairly clear on the different purposes ofPUT
andPOST
.