RESTful OA

RESTful Open Annotation API specification

View the Project on GitHub

Contents

Home
Quickstart
Data model
JSON-LD
OA context
Core API
Extensions

Core API

This page presents the core RESTful Open Annotation API that must be supported by all conforming implementations. Optional features are presented on the extensions page.

Overview

The core API defines two resouce types, the collection resource annotations and individual annotation resources contained in these collections. These resources can be manipulated using HTTP methods in the standard way:

MethodResource
GETAnnotationRetrieve annotation
GETCollectionRetrieve all annotations
PUTAnnotationUpdate annotation
DELETEAnnotationDelete annotation
POSTCollectionCreate annotation

The GET operations for annotations and annotation collections must be implemented by all servers implementing the API. Read-only services may respond with 405 Method Not Allowed to requests using the other methods.

The default content type is application/ld+json, and all servers must accept JSON-LD data and provide responses in JSON-LD when requests specify that it is preferred (using the Accept header).

The JSON-LD context defined in the context documentation is used to represent both annotations and collections, and responses are compacted with respect to this context by default.

The following status codes apply across methods:

The method / resource combinations are specified in detail below.

GET annotation

Retrieve representation of an annotation.

Response: 200 OK and complete representation of annotation.

Example request:

curl -i http://example.org/annotations/123

Example response:

HTTP/1.0 200 OK
Content-Type: application/ld+json

{
  "@context": "/ns/restoa.jsonld",
  "@type": "oa:Annotation",
  "@id": "/annotations/123",
  "target": "/documents/456#char=42,48",
  "body": "Person",
}

Notes:

PUT annotation

Update an annotation.

Request: representation of annotation.

Response: 200 OK and complete representation of annotation.

Example request:

curl -X PUT -i -H 'Content-Type: application/json' -d '
{
  "@context": "/ns/restoa.jsonld",
  "@type": "oa:Annotation",
  "target": "/documents/456#char=42,48",
  "body": "Organization",
}
' http://example.org/annotations/123

Example response:

HTTP/1.0 200 OK
Content-Type: application/ld+json

{
  "@context": "/ns/restoa.jsonld",
  "@type": "oa:Annotation",
  "@id": "/annotations/123",
  "target": "/documents/456#char=42,48",
  "body": "Organization",
  "annotatedBy": [ "/users/foo", "/users/bar" ]
}

Notes:

DELETE annotation

Permanently remove a single annotation.

Response: 204 No Content

Example request:

curl -X DELETE http://example.org/annotations/123

Example response:

HTTP/1.0 204 No Content

GET collection

Retrieve representation of an annotation collection and all annotations contained in the collection.

Response: 200 OK and collection and annotations in JSON-LD. The collection is represented as a named graph.

Example request:

curl -i http://example.org/annotations/

Example response:

HTTP/1.0 200 OK
Content-Type: application/ld+json

{
  "@context": ...
  "@id": "/annotations/",
  "generatedAt": "2012-04-09",
  "@graph":
  [
    {
      "@id": "/annotations/123",
      "target": "/documents/456#char=42,48",
      "body": "Person",
      ...
    },
    {
      "@id": "/annotations/789",
      "target": "/documents/456#char=56,64",
      "body": "Organization",
      ...
    },
  ]
}

Notes:

POST collection

Create annotation.

Request: representation of annotation.

Response: 201 CREATED and complete representation of annotation.

Example request:

curl -X POST -i -H 'Content-Type: application/json' -d '
{
  "@context": "/ns/restoa.jsonld",
  "@type": "oa:Annotation",
  "target": "/documents/456#char=42,48",
  "body": "Person",
}
' http://example.org/annotations/789

Example response:

HTTP/1.0 200 OK
Content-Type: application/ld+json

{
  "@context": "/ns/restoa.jsonld",
  "@type": "oa:Annotation",
  "@id": "/annotations/789",
  "annotatedAt": "2015-03-03T19:16:32+09:00",
  "annotatedBy": "/users/smp",
  "target": "/documents/456#char=42,48",
  "body": "Person"
}

Notes:

Extensions

For optional extensions to this core API, see the extensions page.