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 Plone RESTful API is the portal root. The client can ask for a REST API response by setting the 'Accept' HTTP header to 'application/json':

http

GET /plone HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i http://nohost/plone -H "Accept: application/json" --user admin:secret

httpie

http -j http://nohost/plone -a admin:secret

python-requests

requests.get('http://nohost/plone', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))

This uses so-called ‘content negotiation’

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

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

{
  "@id": "http://localhost:55001/plone", 
  "@type": "Plone Site", 
  "id": "plone", 
  "items": [
    {
      "@id": "http://localhost:55001/plone/front-page", 
      "@type": "Document", 
      "description": "Congratulations! You have successfully installed Plone.", 
      "review_state": "private", 
      "title": "Welcome to Plone"
    }
  ], 
  "items_total": 1, 
  "parent": {}, 
  "sharing": {
    "@id": "http://localhost:55001/plone/@sharing", 
    "title": "Sharing"
  }
}

@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 document. Click on the buttons below to show the different syntaxes for the request.

http

GET /plone/front-page HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i http://nohost/plone/front-page -H "Accept: application/json" --user admin:secret

httpie

http -j http://nohost/plone/front-page -a admin:secret

python-requests

requests.get('http://nohost/plone/front-page', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))
HTTP/1.1 200 OK
Content-Type: application/json

{
  "@id": "http://localhost:55001/plone/front-page", 
  "@type": "Document", 
  "UID": "SomeUUID000000000000000000000001", 
  "allow_discussion": null, 
  "changeNote": "", 
  "contributors": [], 
  "created": "2016-01-21T01:14:48+00:00", 
  "creators": [
    "test_user_1_", 
    "admin"
  ], 
  "description": "Congratulations! You have successfully installed Plone.", 
  "effective": null, 
  "exclude_from_nav": false, 
  "expires": null, 
  "id": "front-page", 
  "language": "", 
  "modified": "2016-01-21T01:24:11+00:00", 
  "parent": {
    "@id": "http://localhost:55001/plone", 
    "@type": "Plone Site", 
    "description": "", 
    "title": "Plone site"
  }, 
  "relatedItems": [], 
  "review_state": "private", 
  "rights": "", 
  "sharing": {
    "@id": "http://localhost:55001/plone/front-page/@sharing", 
    "title": "Sharing"
  }, 
  "subjects": [], 
  "table_of_contents": null, 
  "text": {
    "content-type": "text/plain", 
    "data": "If you're seeing this instead of the web site you were expecting, the owner of this web site has just installed Plone. Do not contact the Plone Team or the Plone mailing lists about this.", 
    "encoding": "utf-8"
  }, 
  "title": "Welcome to Plone"
}

And so on, see