Hi all!
Our team is going to implement some APIs. We committed to use json:api specification, but we struggle to handle correctly the relationship
concept.
We have Project and Components. Each Project contains an ordered set of Components. Each Component could be contained in several Projects. A relationship between the two entities is used to store the position of each Component within a Project. We have identified the following resources:
- Project (a resource)
- Component (a resource)
- ProjectComponent (a relationship resource): this resource is the only way we have found (in our intepretation of json:api) to handle the position of a Component within a Project
I would like to know if the following content is correct in terms of json:api specification.
Project
{
links: {
self: "/project/1"
},
data: [{
id: "1",
type: "project",
attributes: {
title: "Project A"
},
relationships: {
project_components: {
links: {
self: "/project/1/relationships/project_components",
related: "/project/1/project_components"
},
data: [{
id: "A",
type: "ProjectComponent"
},
{
id: "B",
type: "ProjectComponent"
}]
}
}
}]
}
Relationship ProjectComponents
{
links: {
self: "/project/1/relationships/project_components",
related: "/project/1/project_components"
},
data: [{
id: "A",
type: "ProjectComponent"
},
{
id: "B",
type: "ProjectComponent"
}]
}
ProjectComponents
{
links: {
self: "/project/1/project_components"
},
data: [{
id: "A",
type: "ProjectComponent",
attributes: {
position: "1"
},
relationships: {
project: {
links: {
related: "/project/1"
},
data: [{
id: "1",
type: "project"
}]
},
component: {
links: {
related: "/component/A"
},
data: [{
id: "A",
type: "component"
}]
}
}
{
id: "B",
type: "ProjectComponent",
attributes: {
position: "2"
},
relationships: {
project: {
links: {
related: "/project/1"
},
data: [{
id: "1",
type: "project"
}]
},
component: {
links: {
related: "/component/B"
},
data: [{
id: "B",
type: "component"
}]
}
}
}]
}
Component
{
links: {
self: "/components"
},
data: [{
id: "A",
type: "Component",
attributes: {
title: "Component A"
},
relationships: {
project_components: {
links: {
related: "/project/1/project_components/A"
},
data: [{
id: "A",
type: "ProjectComponent"
}]
},
component_questions: {
links: {
self: "/component_questions/A"
},
data: [{
id: "100",
type: "ComponentQuestion"
},{
id: "101",
type: "ComponentQuestion"
}]
}
}
{
id: "B",
type: "Component",
attributes: {
title: "Component B"
},
relationships: {
project_components: {
links: {
related: "/project/1/project_components/B"
},
data: [{
id: "B",
type: "ProjectComponent"
}]
},
component_questions: {
links: {
self: "/component_questions/B"
},
data: [{
id: "200",
type: "ComponentQuestion"
},{
id: "201",
type: "ComponentQuestion"
}]
}
}
}]
}