RE: Trying to understand how templated links work

Hi Martin,

On Wednesday, April 5, 2017 1:00 AM, Martin Bayly wrote:
> Does anyone know of any examples of Template Links as described in the
> vocabulary and what is the relationship between a TemplateLink and an
> IRITemplate.
> 
> https://www.hydra-cg.com/spec/latest/core/#templated-links
> 
> I'm most likely exposing my lack of knowledge about how RDF works
> here. I see that the range of a TemplatedLink is an IRITemplate.

Right. In RDF properties have types too. In the section you referenced, a property "hydra:search" is defined and it is declared to be of type TemplatedLink. That tells a client that it can expect that the value of such a property is a IriTemplate.

You'd use TemplatedLink when you define your vocabulary or create the ApiDocumentation.


> But I'm trying to understand how I would represent this in an API
> response.
> 
> e.g. take the example of the entrypoint for the event-api demo.
> 
> Let's say that the "events" URL actually needed to be a template with
> a query parameter filtering how many events are returned.
> 
> How would you represent that?
> 
> This is the original API response:
> {
>     "@context": "/hydra/event-api/contexts/EntryPoint.jsonld",
>     "@id": "/hydra/event-api/",
>     "@type": "EntryPoint",
>     "events": "/hydra/event-api/events/"
> }
> 
> How would you represent it as a TemplatedLink? Like this?
> {
>     "@context": "/hydra/event-api/contexts/EntryPoint.jsonld",
>     "@id": "/hydra/event-api/",
>     "@type": "EntryPoint",
>     "events": {
>         "@type": "IriTemplate",
>         "template": "/hydra/event-api/events{?pageSize}"
>         "mapping": ...
>     }
> }
> 
> Or something completely different?

No, exactly like that. Additionally the vocabulary [1] would be updated to describe that. Currently it defines that property as

  {
    "@id": "vocab:EntryPoint/events",
    "@type": "hydra:Link",
    "label": "events",
    "description": "The events collection",
    ...
  }

You would change it to

  {
    "@id": "vocab:EntryPoint/events",
    "@type": "hydra:TemplatedLink",
    "label": "events",
    "description": "The events collection",
    ...
  }

To tell the client to expect a template instead of a direct link


> How would something like this be integrated with the concept of
> supported operations/operations?

Nothing changes in that regard. Operations would apply to the resources that you get after expanding the IRI template instead of the resources you would directly point to.


Cheers,
Markus


[1] http://www.markus-lanthaler.com/hydra/event-api/vocab


--
Markus Lanthaler
@markuslanthaler

Received on Thursday, 6 April 2017 06:21:52 UTC