Linked Data for Librarians

by Seth van Hooland and Ruben Verborgh

Part 2 – Module 3: REST

Linked Data for Librarians

by Seth van Hooland and Ruben Verborgh

Part 2 – Module 3: REST

Institute of Museum and Library Services Drexel University College of Computing & Informatics

[an old chest]
©2017 Ruben Verborgh

A Web API is an interface on the server
to expose data & functionality to clients.

Why does the Web scale the way it does?
How should we build for the Web?

The REST architectural style consists of
5 types of mandatory constraints.

  1. client–server constraints
  2. statelessness constraint
  3. cache constraints
  4. layered system constraints
  5. uniform interface constraints

The uniform interface constraints are
unique to the REST architectural style.

REST introduces 4 uniform interface constraints:

  1. identification of resources
  2. resource manipulation through representations
  3. self-descriptive messages
  4. hypermedia as the engine of application state

resource is the main information unit.
An identifier points to at most 1 resource.

A resource is a conceptual relationship:
its value might change over time.

Information resources can have
zero or more representations.

Each message in a REST interaction
should be self-descriptive.

The interaction is driven by
hypermedia controls inside of responses.

The Web implements a uniform interface
through URLs, HTTP, and HTML.

The Web supports all 4 uniform interface constraints:

  1. identification of resources
  2. resource manipulation through representations
  3. self-descriptive messages
  4. hypermedia as the engine of application state

Web resources are conceptual relations
uniquely identified by HTTP URLs.

Web resources are conceptual relations
uniquely identified by HTTP URLs.

Schema visualizing REST resources on the Web

Clients obtain different representations
through HTTP content negotiation.

Clients obtain different representations
through HTTP content negotiation.

Schema visualizing REST representations on the Web

Well-defined HTTP methods & headers
and media types enable self-description.

HTML and other hypermedia documents
can contain hypermedia controls.

The Web is one implementation of REST. Not every website follows the style.

An urban architect cannot control individual buildings.

[the Ghent city pavilion]
©2014 City of Ghent

A REST API is a collection of resources.
Any regular website is in fact a REST API.

A resource should relate
an URL to a concept.

Don’t.

http://​example.org/​songs/​showDetails.php

Do.

http://​example.org/​songs/​3563642

Resources allow many representations
under a single URL.

Don’t.

http://​example.org/​songs/​3563642 results in HTML.

http://​api.example.org/​getObjectJson.php?id=18353113 results in JSON.

Do.

http://​example.org/​songs/​3563642 results in HTML.

And results in JSON.

And results in XML.

Each message should be self-descriptive
and stand on its own.

Don’t.

/songs?artist=5521

/?page=2

/?page=3

Do.

/songs?artist=5521

/songs?artist=5521&page=2

/songs?artist=5521&page=3

The interaction should be
driven by hypermedia.

Don’t.

{
  "title": "War and Peace",
  "artist": {
    "id": 5521

  }
}

Do.

{
  "title": "War and Peace",
  "artist": {
    "id": "http://example.org/
           artists/5521"
  }
}

Servers offering a hypermedia API
enable the follow your nose principle.

To understand hypermedia’s importance,
imagine using any website without it.

http://google.com/

Google logo

You’d need to read the documentation,
and hard-code it.

http://google.com/documentation.html

To use this site,
enter your search term as follows: http://www.google.com/search?q=search+term

Most Web APIs do not follow REST.
They do not focus on the long term.

Exposing cultural heritage metadata
requires a long-term architectural vision.

Using the Europeana website
as a human is straightforward.

Using the Europeana website
as a machine is possible in two ways.

Which one would be easier?

Retrieving an item through the website
as a machine takes one step.

  1. Use the same URL of the item, but ask for JSON.

Using the dedicated Europeana API
is quite complicated.

All of that wasn’t necessary for the website,
even though it contains the exact same information.

Retrieving an item through the API
involves at least 5 steps.

  1. Register for an API key.
  2. Find the right URL template for the API call.
  3. Find out the object ID of your object.
  4. Fill out the template to construct the URL.
  5. Retrieve a representation using this URL.

The URL you obtain from those steps
is personalized and thus volatile.

http://europeana.eu/api/v2/record/9200229/​BibliographicResource_3000135601313.json?wskey=xxxxxxxxx

The JSON cannot be shared nor cached,
and you need the documentation.

{
  "apikey": "xxxxxxxxx",
  "action": "--deprecated--",
  "success": true,
  "statsDuration": 110,
  "requestNumber": 999,
  "object": {
    "type": "IMAGE",
    "edmDatasetName": [ "9200229_Ag_EU_TEL_a1112_LibGent" ],
    "title": [ "Belfort, Botermarkt, Gent klokkentoren (1853)" ],
    "about": "/9200229/BibliographicResource_3000135601313",
    "europeanaAggregation": {
      "about": "/aggregation/europeana/9200229/BibliographicResource_3000135601313",
      "aggregatedCHO": "/item/9200229/BibliographicResource_3000135601313",
      "edmLandingPage": "http://europeana.eu/portal/record/9200229/BibliographicResource_3000135601313.html",
      "edmCountry": { "def": [ "belgium" ] },
      "edmLanguage": { "def": [ "mul" ] },
      "edmRights": {
        "def": [ "https://creativecommons.org/licenses/by-sa/4.0/" ]
      },
      "edmPreview": "http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fadore.ugent.be%2FOpenURL%2Fresolve%3Fsvc_id%3Dmedium%26url_ver%3DZ39.88-2004%26rft_id%3Darchive.ugent.be%3A3107D15A-BB55-11E3-8B3D-86C4D43445F2%3A1&size=LARGE&type=IMAGE"
    },
    "proxies": [
      {
        "about": "/proxy/provider/9200229/BibliographicResource_3000135601313",
        "dcDescription": {
          "def": [
            "Stempel op keerzijde afbeelding: Copyright A.C.L.",
            "Handgeschreven notitie op keerzijde afbeelding: 102308 B"
          ]
        },
        "dcFormat": { "en": [ "Printed" ] },
        "dcIdentifier": { "def": [ "002075264" ] },
        "dcRights": {
          "def": [
            "Reproductierecht Universiteitsbibliotheek Gent",
            "CC BY-SA (4.0)"
          ]
        },
        "dcTitle": {
          "def": [ "Belfort, Botermarkt, Gent klokkentoren (1853)" ]
        },
        "dcType": { "en": [ "Serial" ] },
        "dctermsExtent": {
          "def": [ "1 fotografische druk : : zwart/wit." ]
        },
        "dctermsIsPartOf": {
          "def": [ "http://data.theeuropeanlibrary.org/Collection/a1112" ]
        },
        "dctermsIssued": {
          "def": [
            "1875? - 1930?",
            "[eind 19e-begin 20e eeuw]."
          ]
        },
        "dctermsSpatial": {
          "def": [ "België, Vlaanderen, Oost-Vlaanderen, Gent (9000), Gent (9000)" ]
        },
        "proxyIn": [
          "/aggregation/provider/9200229/BibliographicResource_3000135601313"
        ],
        "proxyFor": "/item/9200229/BibliographicResource_3000135601313",
        "edmType": "IMAGE",
        "europeanaProxy": false
      },
      {
        "about": "/proxy/europeana/9200229/BibliographicResource_3000135601313",
        "proxyIn": [
          "/aggregation/europeana/9200229/BibliographicResource_3000135601313"
        ],
        "proxyFor": "/item/9200229/BibliographicResource_3000135601313",
        "edmType": "IMAGE",
        "europeanaProxy": true
      }
    ],
    "aggregations": [
      {
        "about": "/aggregation/provider/9200229/BibliographicResource_3000135601313",
        "edmDataProvider": {
          "def": [ "Ghent University Library" ]
        },
        "edmIsShownBy": "http://adore.ugent.be/OpenURL/app?type=carousel&id=archive.ugent.be:3107D15A-BB55-11E3-8B3D-86C4D43445F2",
        "edmObject": "http://adore.ugent.be/OpenURL/resolve?svc_id=medium&url_ver=Z39.88-2004&rft_id=archive.ugent.be:3107D15A-BB55-11E3-8B3D-86C4D43445F2:1",
        "edmProvider": {
          "en": [ "The European Library" ]
        },
        "edmRights": {
          "def": [ "https://creativecommons.org/licenses/by-sa/4.0/" ]
        },
        "aggregatedCHO": "/item/9200229/BibliographicResource_3000135601313",
        "webResources": [
          {
            "webResourceEdmRights": {
              "def": [ "https://creativecommons.org/licenses/by-sa/4.0/" ]
            },
            "about": "http://adore.ugent.be/OpenURL/app?type=carousel&id=archive.ugent.be:3107D15A-BB55-11E3-8B3D-86C4D43445F2",
            "textAttributionSnippet": "Belfort, Botermarkt, Gent klokkentoren (1853) - http://europeana.eu/portal/record/9200229/BibliographicResource_3000135601313.html. Ghent University Library. CC BY-SA - https://creativecommons.org/licenses/by-sa/4.0/",
            "htmlAttributionSnippet": "<span about='http://data.europeana.eu/item/9200229/BibliographicResource_3000135601313'><a href='http://europeana.eu/portal/record/9200229/BibliographicResource_3000135601313.html'><span property='dc:title'>Belfort, Botermarkt, Gent klokkentoren (1853)</span></a>. Ghent University Library. <a href='https://creativecommons.org/licenses/by-sa/4.0/' rel='xhv:license http://www.europeana.eu/schemas/edm/rights'>CC BY-SA</a><span rel='cc:useGuidelines' resource='http://www.europeana.eu/rights/pd-usage-guide/'>.</span></span>"
          },
          {
            "webResourceEdmRights": {
              "def": [ "https://creativecommons.org/licenses/by-sa/4.0/" ]
            },
            "about": "http://adore.ugent.be/OpenURL/resolve?svc_id=medium&url_ver=Z39.88-2004&rft_id=archive.ugent.be:3107D15A-BB55-11E3-8B3D-86C4D43445F2:1",
            "textAttributionSnippet": "Belfort, Botermarkt, Gent klokkentoren (1853) - http://europeana.eu/portal/record/9200229/BibliographicResource_3000135601313.html. Ghent University Library. CC BY-SA - https://creativecommons.org/licenses/by-sa/4.0/",
            "htmlAttributionSnippet": "<span about='http://data.europeana.eu/item/9200229/BibliographicResource_3000135601313'><a href='http://europeana.eu/portal/record/9200229/BibliographicResource_3000135601313.html'><span property='dc:title'>Belfort, Botermarkt, Gent klokkentoren (1853)</span></a>. Ghent University Library. <a href='https://creativecommons.org/licenses/by-sa/4.0/' rel='xhv:license http://www.europeana.eu/schemas/edm/rights'>CC BY-SA</a><span rel='cc:useGuidelines' resource='http://www.europeana.eu/rights/pd-usage-guide/'>.</span></span>"
          }
        ],
        "edmPreviewNoDistribute": false
      }
    ],
    "providedCHOs": [
      {
        "about": "/item/9200229/BibliographicResource_3000135601313"
      }
    ],
    "europeanaCompleteness": 7,
    "europeanaCollectionName": [ "9200229_Ag_EU_TEL_a1112_LibGent" ],
    "language": [ "mul" ],
    "timestamp_created_epoch": 1442493422613,
    "timestamp_update_epoch": 1455546713777,
    "timestamp_created": "2015-09-17T12:37:02.613Z",
    "timestamp_update": "2016-02-15T14:31:53.777Z"
  }
}

API keys for representations
(not resources) are a fallacy.

Europeana’s Web API design choices
have consequences for sustainability.

Europeana’s website design choices
have consequences for sustainability.

Read more for a deep understanding of
how REST enables sustainability.

Self-assessment 1: resources

Which statements are true for REST APIs?

  1. Resources do not always have a representation.
    • Yes: for instance, a non-information resource might not have a representation in the API.
  2. Representations do not always belong to a resource.
    • No: REST APIs are resource-oriented, so every representation belongs to a resource.
  3. Resources can have multiple representations.
    • Yes: for instance, a resource might have an HTML and an RDF representation.

Self-assessment 2: representations

Why are different representations useful?

  1. To support different kinds of servers.
    • No, representations do not directly influence the type of server.
  2. To support different kinds of clients.
    • Yes: different clients (browsers, Linked Data consumers, …) might have different needs.
  3. To support different kinds of resources.
    • No, the question is rather why a single resource can have different representations.

Self-assessment 3: hypermedia

What does the hypermedia constraint of REST entail?

  1. We should only use HTML representations.
    • No: HTML does support hypermedia controls, but others support this as well.
  2. Servers should include links to next steps in their responses.
    • Yes: that way, the interaction can be completed through those links (as opposed to through external documentation).
  3. Clients can follow their nose through the API.
    • Yes: clients do not need a previously agreed-on list of steps, but can just follow the links they receive.

Self-assessment 4: consequences

What makes the Europeana API more difficult than the website?

  1. You need an API key.
    • Yes, even though both expose the same information.
  2. You cannot use it without documentation.
    • Yes, even though you don’t need documentation for the website, which exposes the same information.
  3. They use multiple representations.
    • No, only the website uses multiple representations.