Skip to content

Store and expose links in _meta #8

Description

@usu

Assuming the following API payload which contains a link that is named the same as an embedded collection:

{
    "name": "Book No #3",
    "_links": {
        "self": {
            "href": "/books/3"
        },
        "chapters": {
            "href": "/chapters?book=3"
        }
    },
    "_embedded": {
        "chapters": [
            {
                "_links": {
                    "self": "/chapters/1028"
                }
            },
            {
                "_links": {
                    "self": "/chapters/1029"
                }
            },
        ]
    }
}

Current behavior
I cannot read the chapters links, as this.api.get('/books/3').chapters() is overwritten by the embedded collection.

let book = this.api.get('/books/3')
console.log(book.chapters()._meta.self) // --> undefined

Proposed behavior
Expose all links in _meta object.

let book = this.api.get('/books/3')
console.log(book._meta.links.chapters) // --> '/chapters?book=3'
this.api().post(book._meta.links.chapters, { title: 'Awesome new chapter' } ) 

This could help to avoid the need for templated links when posting to new objects.

Possible workaround
A workaround possible today is to use a different name for the link, e.g. chaptersLink and then do:

let book = this.api.get('/books/3')
console.log(book.chaptersLink()._meta.self) // --> '/chapters?book=3'
this.api().post(book.chaptersLink()._meta.self, { title: 'Awesome new chapter' }

However, with this I'll trigger an unnecessary API request to chaptersLink().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions