How to do either operation in IRItemplate in a Hydra:Operation?

132 views Asked by At

My hydra vocab is similar to Markus-lanthaler Vocab.Here is one of my operation on User Class to retrieve collection of Users.

{
  "@id": "payu:retrieve_users",
  "@type": "hydra:Operation",
  "method": "GET",
  "label": "Retrieve users",
  "description": "Retrieves Users",
  "expects": null,
  "returns": "hydra:Collection",
  "IriTemplate" : {
    "@type" : "IriTemplate",
    "template" : "{?userIds,firstName,lastName}",
    "variableRepresentation": "BasicRepresentation",
    "mapping" : [
      {
        "@type" : "IriTemplateMapping",
        "variable" : "userIds",
        "property" : "hydra:property",
        "required" : false
      },
      {
        "@type" : "IriTemplateMapping",
        "variable" : "firstName",
        "property" : "hydra:property",
        "required" : false
      },
      {
        "@type" : "IriTemplateMapping",
        "variable" : "lastName",
        "property" : "hydra:property",
        "required" : false
      }
    ]
  }
}

As you can see in IRItemplate

"template" : "{?userIds,firstName,lastName}"

so I want to get control over retrieve either a third person will be able to retrieve through (userIds) or (firstName,lastName).

Should I make two separate hydra Operations having IRItemplate :
In First Operation:

"template" : "{?userIds}"

In Second Operation:

"template" : "{?firstName,lastName}"

Or Is there any existing way to do this in Hydra Specification using single operation ?

1

There are 1 answers

0
Markus Lanthaler On

Currently there's no way to specify that for a single operation. You'll need to have two operations. Also, you need to associate the operation to the IriTemplate and not the other way round:

  {
    "@type" : "IriTemplate",
    "template" : "{?userIds,firstName,lastName}",
    ...
    "operation": {
      "@id": "payu:retrieve_users",
      "@type": "hydra:Operation",
      "method": "GET",
      ...
    }
  }