Store and expose links in _meta
- Dominant language
- JavaScript
- Stars
- 8
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Assuming the following API payload which contains a link that is named the same as an embedded collection:
```yaml
{
"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.
```js
let book = this.api.get('/books/3')
console.log(book.chapters()._meta.self) // --> undefined
```
**Proposed behavior**
Expose all links in _meta object.
```js
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:
```js
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()`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.