Skip to content

Proposal to reserve "virtuals" member at top level of resource objects #575

@cziegenberg

Description

@cziegenberg

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy