Skip to content

OpenAPI HATEOAS linking #60

@rduyme

Description

@rduyme

We validated the update of the OpenAPI with defined API links in https://docs.google.com/document/d/12VOXrgpISSXsIVZtGZ_3zbNIZkTQy4hpMYXI04MtFVQ/edit?tab=t.0#heading=h.3brndhbrt82y

Silvio requested to have these links separated from the core entities model in the meta section.

Here is proposition for an evolution of the meta section. I had to put it in the @graph to have compatible triple.
Note that it is still possible to have embedded approach in product-cc. It produces the same triples.

The main change was to add an as:items to have all the links information in the meta which is already an as:CollectionPage in the current OpenAPI api context (https://skg-if.github.io/api/openapi/ver/1.0.0/context/skg-if-api.json)

We will add new aliases in the skg-if-api.json

-- EXISTING aliases in  https://skg-if.github.io/api/openapi/ver/1.0.0/context/skg-if-api.json
"search_result_page": "as:CollectionPage"
"search_result":"as:Collection"
"part_of": "as:partOf"
 "total_items": "as:totalItems"
 "next_page":"as:next"
  "first_page":"as:first" 
"last_page": "as:last"
 "prev_page":"as:prev"
-- NEW aliases
"link": "as:Link",
 "rel": "as:rel",
 "href": "as:href",
 "result_api_links": "as:items",
 "entity_api_links": "as:url",

Here is the raw not aliased version.

{
  "@context": [
    "https://w3id.org/skg-if/context/1.1.0/skg-if.json",
    {
      "as": "http://www.w3.org/ns/activitystreams#",
      "meta": "@nest",
      "results": "@set"
    }
    ],
  "@graph" : [
    {
      "meta": {
        "@id": "https://cessda.com/skg-if/api/products?filter=product_type:literature&page=1",
     	"@type": "as:CollectionPage",
      	"as:next": {
            "local_identifier": "https://cessda.com/skg-if/api/products?filter=product_type:literature&page=2",
            "@type": "as:CollectionPage"
          },
      	 "as:partOf": {
            "local_identifier": "https://cessda.com/skg-if/api/products?filter=product_type:literature",
            "@type": "as:Collection",
          	"as:totalItems": 54231
          },
          "as:items" : [
          {
              "@id": "https://w3id.org/cessda/product-aaa",
              "as:url": {
                "@type": "as:Link",
                "as:rel": "self",
                "as:href": "https://cessda.com/skg-if/api/products/aaa"
              }
          },
          {
              "@id": "https://w3id.org/cessda/product-bbb",
              "as:url": {
                "@type": "as:Link",
                "as:rel": "self",
                "as:href": "https://cessda.com/skg-if/api/products/bbb"
              }
          }
        ]
      
}},
    { "results" : [
    { 
      "@id": "https://w3id.org/cessda/product-bbb",
      "entity_type": "product"
    },
    { 
      "@id": "https://w3id.org/cessda/product-aaa",
      "entity_type": "product"
    },
     { 
      "@id": "https://w3id.org/cessda/product-ccc",
      "entity_type": "product",
  // note it is still possible to have an embedded section producing the same triples as product-bbb and product-aaa with API links in the meta
       "as:url": {
                "@type": "as:Link",
                "as:rel": "self",
                "as:href": "https://example.com/skg-if/api/products/ccc"
       }
     }]}

  ]
}

Playground

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions