Introduction

A hypermedia API provides an entry point to the API, which contains hyperlinks the clients can follow. Just like a human user of a regular website, who knows the initial URL of a website and then follows hyperlinks to navigate through the site. This has the advantage that the client only needs to understand how to detect and follow links. The URLs (apart from the inital entry point) and other details of the API can change without breaking the client.

The entry point to the RESTful API is the portal root. The client can ask for a REST API response by setting the Accept HTTP header to application/json:

GET /news HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

The server will then respond with the portal root in the JSON format:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "title": "Welcome to Volto",
  "blocks": {
    "495efb73-cbdd-4bef-935a-a56f70a20854": {
      "text": {
        "blocks": [
          {
            "key": "9f35d",
            "data": {},
            "text": "Congratulations! You have succesfully installed Volto.",
            "type": "unstyled",
            "depth": 0,
            "entityRanges": [],
            "inlineStyleRanges": []
          }
        ],
        "entityMap": {}
      },
      "@type": "text"
    },
    "79ba8858-1dd3-4719-b731-5951e32fbf79": {
      "@type": "title"
    }
  },
  "effective": "2022-04-02T20:00:00.000Z",
  "description": "Congratulations! You have successfully installed Volto.",
  "blocks_layout": {
    "items": [
      "79ba8858-1dd3-4719-b731-5951e32fbf79",
      "495efb73-cbdd-4bef-935a-a56f70a20854"
    ]
  },
  "items": [
    {
      "title": "Events",
      "blocks": {
        "79ba8858-1dd3-4719-b731-5951e32fbf79": {
          "@type": "title"
        }
      },
      "effective": "2022-04-02T20:30:00.000Z",
      "blocks_layout": {
        "items": ["79ba8858-1dd3-4719-b731-5951e32fbf79"]
      },
      "@id": "http://localhost:8000/events",
      "@type": "Folder",
      "id": "events",
      "created": "2022-04-02T20:30:00.000Z",
      "modified": "2022-04-02T20:30:00.000Z",
      "UID": "1a2123ba-14e8-4910-8e6b-c04a40d72a41",
      "is_folderish": true,
      "review_state": "published",
      "lock": {
        "locked": false,
        "stealable": true
      }
    },
    {
      "title": "News",
      "blocks": {
        "79ba8858-1dd3-4719-b731-5951e32fbf79": {
          "@type": "title"
        }
      },
      "effective": "2022-04-02T20:22:00.000Z",
      "description": "News Items",
      "blocks_layout": {
        "items": ["79ba8858-1dd3-4719-b731-5951e32fbf79"]
      },
      "@id": "http://localhost:8000/news",
      "@type": "Folder",
      "id": "news",
      "created": "2022-04-02T20:22:00.000Z",
      "modified": "2022-04-02T20:22:00.000Z",
      "UID": "32215c67-86de-462a-8cc0-eabcd2b39c26",
      "is_folderish": true,
      "review_state": "published",
      "lock": {
        "locked": false,
        "stealable": true
      }
    },
    {
      "title": "Users",
      "blocks": {
        "79ba8858-1dd3-4719-b731-5951e32fbf79": {
          "@type": "title"
        }
      },
      "effective": "2022-04-02T20:24:00.000Z",
      "blocks_layout": {
        "items": ["79ba8858-1dd3-4719-b731-5951e32fbf79"]
      },
      "@id": "http://localhost:8000/users",
      "@type": "Folder",
      "id": "users",
      "created": "2022-04-02T20:24:00.000Z",
      "modified": "2022-04-02T20:24:00.000Z",
      "UID": "80994493-74ca-4b94-9a7c-145a33a6dd80",
      "is_folderish": true,
      "review_state": "published",
      "lock": {
        "locked": false,
        "stealable": true
      }
    }
  ],
  "@id": "http://localhost:8000",
  "@type": "Site",
  "id": "root",
  "created": "2022-04-02T20:00:00.000Z",
  "modified": "2022-04-02T20:00:00.000Z",
  "UID": "92a80817-f5b7-400d-8f58-b08126f0f09b",
  "is_folderish": true,
  "review_state": "published",
  "lock": {
    "locked": false,
    "stealable": true
  }
}

@id is a unique identifier for resources (IRIs). The @id property can be used to navigate through the web API by following the links.

@type sets the data type of a node or typed value

items is a list that contains all objects within that resource.

A client application can “follow” the links (by calling the @id property) to other resources. This allows to build a losely coupled client that does not break if some of the URLs change, only the entry point of the entire API (in our case the portal root) needs to be known in advance.

Another example, this time showing a request and response for a folder.

GET /news HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

HTTP/1.1 200 OK
Content-Type: application/json

{
  "title": "News",
  "blocks": {
    "79ba8858-1dd3-4719-b731-5951e32fbf79": {
      "@type": "title"
    }
  },
  "description": "News Items",
  "blocks_layout": {
    "items": [
      "79ba8858-1dd3-4719-b731-5951e32fbf79"
    ]
  },
  "items": [],
  "@id": "http://localhost:8000/news",
  "@type": "Folder",
  "id": "news",
  "created": "2022-04-02T20:22:00.000Z",
  "modified": "2022-04-02T20:22:00.000Z",
  "effective": "2022-04-02T20:22:00.000Z",
  "UID": "32215c67-86de-462a-8cc0-eabcd2b39c26",
  "owner": "admin",
  "is_folderish": true,
  "review_state": "published",
  "lock": {
    "locked": false,
    "stealable": true
  }
}