Inherit
Content items are arranged in a hierarchy. Each content item has a parent, each of which may have its own parent, continuing all the way to the site root. Together, the chain of parents are ancestors of the content item.
The @inherit
service makes it possible to access data from a behavior defined on one of these ancestors.
To use the service, send a GET
request to the @inherit
endpoint in the context of the content item that is the starting point for inheriting. Specify the expand.inherit.behaviors
parameter as a comma-separated list of behaviors.
GET /news/@inherit?expand.inherit.behaviors=navigation_root HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.getInherit({
token: login.data.token,
path: '/news',
query: {
'expand.inherit.behaviors': 'navigation_root',
},
});
For each behavior, the service will find the closest ancestor which provides that behavior. The result includes from
(the @id
and title
of the item from which values were inherited) and data
(values for any fields that are part of the behavior).
HTTP/1.1 200 OK
Content-Type: application/json
{
"@id": "http://localhost:8080/news/@inherit",
"navigation_root": {
"data": {},
"from": {
"@id": "http://localhost:8080",
"title": "Welcome to Nick!"
}
}
}
Ancestor items for which the current user lacks the View
permission will be skipped.