Regaez / grav-plugin-api

A REST API plugin for GravCMS
MIT License
27 stars 6 forks source link

feat: improve PageResource hypermedia linking #54

Closed Regaez closed 4 years ago

Regaez commented 5 years ago

The children property should be moved out of the PageResource attributes and added to the links hypermedia.

For example:

"links": {
    "self": "http://localhost:8080/parent-page",
    "children": [
        "http://localhost:8080/parent-page/child-1",
        "http://localhost:8080/parent-page/child-2"
    ],
    "related": {
        "self": "http://localhost:8080/api/pages/parent-page",
        "children": [
            "http://localhost:8080/api/pages/parent-page/child-1",
            "http://localhost:8080/api/pages/parent-page/child-2"
        ],
        "resource": "http://localhost:8080/api/pages/"
    }
}

Similarly, a child page should have a parent link:

"links": {
    "self": "http://localhost:8080/parent-page/child-1",
    "parent": "http://localhost:8080/parent-page",
    "related": {
        "self": "http://localhost:8080/api/pages/parent-page/child-1",
        "parent": "http://localhost:8080/api/pages/parent-page",
        "resource": "http://localhost:8080/api/pages/"
    }
}

Similarly, a child page should have a siblings field for pages at the same level:

"links": {
    "self": "http://localhost:8080/parent-page/child-1",
    "parent": "http://localhost:8080/parent-page",
    "siblings": [
        "http://localhost:8080/parent-page/child-2"
    ],
    "related": {
        "self": "http://localhost:8080/api/pages/parent-page/child-1",
        "parent": "http://localhost:8080/api/pages/parent-page",
        "siblings": [
            "http://localhost:8080/api/pages/parent-page/child-2"
        ],
        "resource": "http://localhost:8080/api/pages/"
    }
}
Regaez commented 5 years ago

Perhaps related should be renamed to api (since it's currently only API links)? 🤔