HydraCG / Specifications

Specifications created by the Hydra W3C Community Group
Other
138 stars 26 forks source link

Specifying operations on TemplatedLink objects #118

Closed tpluscode closed 6 years ago

tpluscode commented 7 years ago

I wasn't sure how to phrase the title but I hope it's clear enough.

I'd asked in the past about a away to specify operations which have a variable target (ie. an IriTemplate). It just dawned on me that I may have been looking at this from the wrong side. Please help me verify my assumptions and possible usage.

Given that the templated link is a property, and a hydra:Resource, it should be possible to attach an operation to it, right? So, assuming ex:tag is a hydra:TemplatedLink, would it be legal to have:

{
  "ex:tag": {
    "@type": "IriTemplate",
    "template": "http://example.com/tag/{tag}",
    "mappings": [{ "variable": "tag" }],
    "operation": [
      {
        "method": "POST",
        "expects": { "@type": "ex:NotificationRequest" }
      },
      {
        "method": "DELETE"
      }
    ]
  }
}

I don't see anything that contradicts the semantics of current vocab. Does the above come close to resolving #100.

By extension, I believe that if we allowed hydra:returns on IriTemplate (#50) then it would be possible to take advantage of hydra:SupportedOperation to define actions possible to perform on templates targets.

{
  "ex:tag": {
    "@type": "IriTemplate",
    "template": "http://example.com/tag/{tag}",
    "mappings": [{ "variable": "tag" }],
    "returns": "ex:Tag"
  }
}

Where ex:Tag could support the DELETE/POST operations inlined in the first snippet.

cr3a7ure commented 7 years ago

Looking the vocabulary diagram and the spec, hydra:Link and hydra:TemplatedLink seems to have the same meaning. Although I can't see a single reference to a template that it's name suggests.
Supposing the above is true, we can attach operations to hydra:TemplatedLink the same way as hydra:Link.

But while hydra:IriTemplate has a well defined mapping hydra:TemplatedLink seems needless. So using either of them (which one seems right though?) should be enough to attach an operation to it, while returns is contained inside the operation as usual and not at the outer node.

I'm pretty new to all this, don't take my word.


After some research and reviewing the spec: The hydra:search definition

{
      "@id": "hydra:search",
      "@type": "hydra:TemplatedLink",
      "comment": "A IRI template that can be used to query a collection.",
      "label": "search",
      "range": "hydra:IriTemplate",
      "status": "testing"
    },
    {
      "@id": "hydra:TemplatedLink",
      "@type": "hydra:Class",
      "comment": "A templated link.",
      "label": "Templated Link",
      "subClassOf": [
        "hydra:Resource",
        "rdf:Property"
      ],
      "status": "testing"
    },

So we get this for search property:

hydra:search: {
"@type": "hydra:IriTemplate",
    "hydra:template": "",
    "hydra:variableRepresentation": "BasicRepresentation",
    "hydra:mapping": [ ]
}

And the property defined below from event api and a recent email

{
            "@id": "vocab:EntryPoint",
            "@type": "hydra:Class",
            "subClassOf": null,
            "label": "EntryPoint",
            "description": "The main entry point or homepage of the API.",
            "supportedOperation": [
                {
                    "@id": "_:entry_point",
                    "@type": "hydra:Operation",
                    "method": "GET",
                    "label": "The APIs main entry point.",
                    "description": null,
                    "expects": null,
                    "returns": "vocab:EntryPoint",
                    "statusCodes": []
                }
            ],
            "supportedProperty": [
                {
                    "property": {
                        "@id": "vocab:EntryPoint/events",
------>               "@type": "hydra:Link", <--- "hydra:TemplatedLink"
                        "label": "events",
                        "description": "The events collection",
                        "domain": "vocab:EntryPoint",
                        "range": "vocab:EventCollection",
                        "supportedOperation": [
                            {
                                "@id": "_:event_collection_retrieve",
                                "@type": "hydra:Operation",
                                "method": "GET",
                                "label": "Retrieves all Event entities",
                                "description": null,
                                "expects": null,
                                "returns": "vocab:EventCollection",
                                "statusCodes": []
                            }
                        ]
                    },
                    "hydra:title": "events",
                    "hydra:description": "The events collection",
                    "required": null,
                    "readonly": true,
                    "writeonly": false
                }
            ]
        },

Where should the { "@type": "hydra:IriTemplate" } be specified?

tpluscode commented 7 years ago

AFAIK hydra:Link is just a property. It is a hint for a hydra client which tells that client that it can expect something interesting when dereferencing the linked resource.

The hydra:TemplatedLink on the other hand doesn't link to a specific resource but to a whole range of resources whose URIs are constructed by substituting the template variables.

In other words, I think of hydra:Link as part of your domain graph. The template however, is hydra-specific way to have the client construct URLs which cannot be supplied by the server. Links connect resources two resources in an API. Templated link connects a resource and a hydra:IriTemplate

Where should the { "@type": "hydra:IriTemplate" } be specified?

You mean in the events API? I don't see a templated link there. But in general, you use it with templated link as in the hydra:search snippet above.

cr3a7ure commented 7 years ago

Check the link at mail list. To my understanding Markus use it like interchangeable terms.

tpluscode commented 7 years ago

Not how I understand that email. @lanthaler answers that to support UriTemplate, the events property would have to be changed from "@type": "hydra:Link" to "@type": "hydra:TemplatedLink". That way it will point to template and not the collection resource itself.

tpluscode commented 6 years ago

I'm closing this for now. Use case 5.1 gives an example of using operations on an IriTemplate. As for supported operations, let discuss on #50.