I'm designing a REST API and despite trawling a number of best practice guides I can't find much relating to the best practice of handling the disparity between representation structure needed for a POST
vs the same representation structure returned from a GET
.
GET
for a dummy user
representation might look like this:
{
"id": 1234,
"created": "2012-04-23T18:25:43.511Z",
"username": "[email protected]",
"name": "John Doe"
}
However, POST
for the same dummy user
representation cannot specify certain properties (namely the id
and created
):
{
"username": "[email protected]",
"name": "John Doe"
}
Obviously this is an overly simplified example but given that the user cannot specify certain fields (and it might not always be obvious which ones are pertinent to the applied method) is it best practice to create separate representations for each or to expect the most complete version and handle the data disparity transparently on the server?
Despite the apparent ease of having a single representation and handling the disparity server side I am worried that this would be a bad experience for a user if it wasn't clear which values can be specified (or altered using PUT
for example). If the tendency is to create separate representations is there a naming convention to apply to the representation definition?
e.g. i_user
for incoming user and o_user
for outgoing user. Or user_full
and user_min
or user
and .user
etc.
Update: My overly simplified example perhaps didn't properly illustrate the issue. Imagine a representation that has 50 properties (for example a server representation with all its monitoring attributes - cpu, ram, temp, storage_drive_a, storage_drive_b, file_permission etc.) Of these 50 properties, 30 are read only properties and 20 of these are values that can be set.