ditto icon indicating copy to clipboard operation
ditto copied to clipboard

Retrieve thing metadata when not retrieving complete thing

Open thjaeckle opened this issue 5 years ago • 0 comments

With #680 (addition of _metadata to a thing) now arbitrary metadata may be added to the JSON hierarchy of a thing.

This metadata can also be queried, but currently only when retrieving the complete thing, e.g.:

GET /api/2/things/org.eclipse.ditto:fancy-car?fields=thingId,features,_revision,_metadata

response:
{
  "thingId": "org.eclipse.ditto:fancy-car",
  "features": {
    "Vehicle": {
      "properties": {
        "speed": 42
      }
    }
  },
  "_revision": 23,
  "_metadata": {
    "features": {
      "Vehicle": {
        "properties": {
          "speed": {
            "issuedAt": "some timestamp ...."
          }
        }
      }
    }
  }
}

The same is true for the Ditto Protocol JSON API.

As an enhancement of enabling that basic query we should add the possibility to query for metadata even when doing a "partial retrieve", e.g. via HTTP:

GET /api/2/things/org.eclipse.ditto:fancy-car/features/Vehicle/properties/speed

response payload:
42

Now, the "fields" selector is not supported at this level "/features/Vehicle/properties/speed" and this would also be strange as strictly speaking at this location in the JSON there is no metadata.

So I suggest to e.g. define a HTTP header (or in addition a HTTP query param) in order to select metadata. The HTTP response would include the requested metadata (if it was existing) as HTTP response header.

HTTP Example:

GET /api/2/things/org.eclipse.ditto:fancy-car/features/Vehicle/properties/speed?get-metadata=issuedAt

response payload:
42

response headers:
  metadata: "[{"issuedAt": "some timestamp ...."}]"

The format could be just a comma separated list of metadata to retrieve relatively to the selected path.

Any thoughts and opinions on that @JulianFeinauer and @jufickel-b ?

thjaeckle avatar Aug 25 '20 15:08 thjaeckle