Content relations explained




Understanding how ACP deals with relationships between resources is probably the hardest part of the API, but still very important as content resources most of the time are connected to others in one way or another. In this chapter we try to give you an in-depth understanding that should get you started.

Relation

A relation are the relationship between two content resources.
Eg: An image used inside a story will appear as an image relation in the story.

A relation is considered a resource on its own. But it will always live inside the context of the content resource where it origins. ACP always embeds the relation resources inside content resources, and do not provide separate endpoints for them.

It may link to another content object. In the scenario where it is linked to a content object, the data fields within the relation may or may not be a copy of the fields found in the linked content object itself. It might seem odd that you can have a relation that are not really pointing to another content object, but this allows us to simplify the API and embed objects from outside our content sphere. It also allows us to override fields like a title within the context of another content object.

Types

Relations are separated into different types. Normally there will be one relation type per content type. But it perfectly ok to have relation types that do not link to a content object at all.

Currently we have the following relation types:

contentRelation
A relation linking to another content resource in the API. Note that this is not the same as a content type even though there is a strong link between these two.
imageRelation
An extension of contentRelation with additional information you will need when dealing with images. Will link to an image resource in the API as well as to the image url itself.
videoRelation
An extension of contentRelation with additional video information you will need. Will link to a video resource in the API.
markupRelation
A special contentRelation containing plain HTML markup.

EXAMPLE


Fields

All relations will have attributes called fields in ACP. What fields you will find depends on the relation type. Based on internal usage of ACP, each relation type contains the fields we think you will need when rendering the relation in your presentation layer.

In version 2 of the ACP Composer API we will provide schemas describing all the expected fields per relation type. But for now you will just have to get an understanding from the field names.

Example of fields found in a contentRelation:
{
"fields": {
"relationGroup": "com.escenic.inlineRelations",
"quote": "Det er flere innbyggere i Gjøvik enn det er helsetilbud til.",
"color": "greenLight",
"lastModifiedDate": "2016-04-19T18:30:22.000+0200",
"source": "Kim Roar Sandli, Gjøvik allmennlegeforening",
"inlineid": "_59d5806d-0d98-4b1c-8e59-74781bf67c36",
"id": "5-35-259768",
"relativeUrl": "/legesitat/x/5-35-259768",
"title": "Legesitat"
}
}

Inline Relations

An inline relation is a regular relation used inside a field in a content resouce.

Often a writer wants to place elements like images, videos, maps, and other types of content inside the body of an article. Actually this has become more the standard way of presenting content over the last couple of years.
<amedia-embed id="https://services.api.no/api/acpcomposer/v1.1/content/5-35-259768" inlineid="_59d5806d-0d98-4b1c-8e59-74781bf67c36">
<a href="/legesitat/x/5-35-259768">Legesitat</a></amedia-embed>&nbsp;</p>

{
"type": "contentRelation",
"_links": {
"self": {
"href": "https://services.api.no/api/acpcomposer/v1.1/content/5-35-259768",
"type": "http://localhost:8080/webservice/publication/abc/escenic/model/quote"
}
},
"title": "Legesitat",
"inline": true,
"fields": {
"relationGroup": "com.escenic.inlineRelations",
"quote": "Det er flere innbyggere i Gjøvik enn det er helsetilbud til.",
"color": "greenLight",
"lastModifiedDate": "2016-04-19T18:30:22.000+0200",
"source": "Kim Roar Sandli, Gjøvik allmennlegeforening",
"inlineid": "_59d5806d-0d98-4b1c-8e59-74781bf67c36",
"id": "5-35-259768",
"relativeUrl": "/legesitat/x/5-35-259768",
"title": "Legesitat"
},
"model": "quote"
}