Collection Interaction Flow

From Hydra Community Group

Without Pagination

GET /markus

{
  "@id": "/markus",
  "givenName": "Markus",
  "familyName": "Lanthaler",
  "friends": "/markus/friends",
  ...
}


GET /markus/friends

{
  "@id": "/markus/friends",
  "@type": "Collection",
  "totalItems": 578,
  "member": [ ... ],
  "view": {
    "@type": "ViewTemplate",
    "template": "/markus/friends{?first,last}",
    "mapping": [
      { "variable": "first", "property": "schema:givenName" },
      { "variable": "last", "property": "schema:familyName" }
    ],
    "filterSpecification": {
      "operator": "AND",
      "operands": [ 
        { "variable": "first" }, 
        { "variable": "last" }
      ]
    }
  }
}


GET /markus/friends?first=Ruben

{
  "@id": "/markus/friends",
  "@type": "Collection",
  "totalItems": 578
  "member": [
    {
      "@id": "/ruben",
      "givenName": "Ruben",
      "familyName": "Verborgh",
    },
    ...
  ],
  "view": [
    {
      "@id": "/markus/friends?first=Ruben",
      "@type": "PartialCollectionView",
      "totalItems": 15
    },
    {
      "@type": "ViewTemplate",
      "template": "/markus/friends{?first,last}",
      "mapping": [
        { "variable": "first", "property": "schema:givenName" },
        { "variable": "last", "property": "schema:familyName" }
      ],
      "filterSpecification": {
        "operator": "AND",
        "operands": [ 
          { "variable": "first" }, 
          { "variable": "last" }
        ]
      }
    }
  ]
}


With Pagination

GET /markus

{
  "@id": "/markus",
  "givenName": "Markus",
  "familyName": "Lanthaler",
  "friends": "/markus/friends",
  ...
}


GET /markus/friends

The server either redirects the client to /markus/friends?page=1 or sets the Content-Location of the response to that URL. Without that, the client wouldn't know that it got something else than what it requested.

{
  "@id": "/markus/friends",
  "@type": "Collection",
  "totalItems": 578,
  "member": [ ... ],
  "view": [
    {
      "@id": "/markus/friends?page=1",
      "@type": "PartialCollectionView",
      "totalItems": 10
      "first": "/markus/friends?page=1",
      "next": "/markus/friends?page=2",
      "last": "/markus/friends?page=58"
    },
    {
      "@type": "ViewTemplate",
      "template": "/markus/friends{?first,last}",
      "mapping": [
        { "variable": "first", "property": "schema:givenName" },
        { "variable": "last", "property": "schema:familyName" }
      ],
      "filterSpecification": {
        "operator": "AND",
        "operands": [ 
          { "variable": "first" }, 
          { "variable": "last" }
        ]
      }
    }
  ]
}


GET /markus/friends?first=Ruben

Again, the server either redirects the client to /markus/friends?first=Ruben&page=1 or sets the Content-Location of the response to that URL. Without that, the client wouldn't know that it got something else than what it requested.

{
  "@id": "/markus/friends",
  "@type": "Collection",
  "totalItems": 578
  "member": [
    {
      "@id": "/ruben",
      "givenName": "Ruben",
      "familyName": "Verborgh",
      ...
    }
  ],
  "view": [
    {
      "@id": "/markus/friends?first=Ruben",
      "@type": "PartialCollectionView",
      "totalItems": 15
    },
    {
      "@id": "/markus/friends?first=Ruben&page=1",
      "@type": "PartialCollectionView",
      "totalItems": 10,
      "first": "/markus/friends?first=Ruben&page=1",
      "next": "/markus/friends?first=Ruben&page=2",
      "last": "/markus/friends?first=Ruben&page=2"
    },
    {
      "@type": "ViewTemplate",
      "template": "/markus/friends{?first,last}",
      "mapping": [
        { "variable": "first", "property": "schema:givenName" },
        { "variable": "last", "property": "schema:familyName" }
      ],
      "filterSpecification": {
        "operator": "AND",
        "operands": [ 
          { "variable": "first" }, 
          { "variable": "last" }
        ]
      }
    }
  ]
}


Other Proposals