How to design API response for page builder feature, specifically form builder.
In admin user can create blocks, define the order for each and add some attributes.
On frontend result should look something like this:
So, my idea is to have /filter_blocks
endpoint which will return the array of filter_block
resources:
{
data: [
{
id: "1",
type: "filter_blocks",
attributes: {
name: "Filter 1",
order: 0,
},
},
{
id: "2",
type: "filter_blocks",
attributes: {
name: "Filter 2",
order: 1,
},
},
{
id: "3",
type: "filter_blocks",
attributes: {
name: "Filter 3",
order: 2,
},
},
{
id: "4",
type: "filter_blocks",
attributes: {
name: "Filter 4",
order: 3,
},
}
],
}
My question here is how to define other uncommon attributes/relations like:
Filter 1
has toOne relation to checkbox
{
id: "1",
type: "checkbox",
attributes: {
name: "Option 1",
},
}
Filter 2
has toOne relation to range
{
id: "1",
type: "range",
attributes: {
min: 0,
max: 250,
},
}
Filter 3
has toOne relation to rating
{
id: "1",
type: "rating",
attributes: {
icon: "star",
},
}
Filter 4
has toMany relation to checkbox
[{
id: "1",
type: "checkbox",
attributes: {
name: "Option 1",
},
},
{
id: "2",
type: "checkbox",
attributes: {
name: "Option 1",
},
}]