-
Notifications
You must be signed in to change notification settings - Fork 890
Description
The spec knows "attributes" but not "virtual attributes" (or "derived attributes"). This type of attribute is usually calculated from the values of other attributes of the same resource (or of related resources).
The problem with these attributes is, that they cannot be updated directly (only by updating the attributes they are derived from), so they are read-only and MUST NOT be used in CREATE/UPDATE requests.
Examples for this type of attribute:
- age (calculated from the date of birth and the current time)
- item total price (calculated from the number of items and the single price)
- order total price (calculated from the total prices of related order items)
The only way to handle this in the current version of the spec is to reply with a "409 Conflict" error, but this error is also used for other conflicts, e.g. with client generated ids.
This conflict could be easily prevented by excluding the derived attributes from the request - but to be able to do that, the client needs to know which attributes are "virtual".
Suggestion:
Reserve a new member "virtuals" at the top level of resource objects, based on the suggested change #573. They MUST share the same namespace with the other resource attributes.
{
"id": "1",
"type": "person",
"attributes": {
"firstname": "Justin",
"lastname": "Timberlake",
"signature": "http://commons.wikimedia.org/wiki/File:Justin_Timberlake_signature.svg",
"date-of-birth": "1981-01-31"
},
"virtuals": {
"age": 34
}
}