Hi everyone! I have been a silent reader for a while and will now for the first time chime into the discussion. First though, thanks for all your work, flarum is turning into a fantastic piece of software! 🚀
I have been playing with the API and have noticed a few quirks, maybe you can help to clarify..
default include
Looking at the code there are several default includes. To keep my requests as small as possible I would like to disable those. However, I can only add more but cannot disable the default ones. According to the JSON:API specification, this must not happen.
If an endpoint supports the include parameter and a client supplies it, the server MUST NOT include unrequested resource objects in the included section of the compound document.
selecting fields
If I use the fields parameter to select, which attributes I want included, this will omit the relationships. See example below.
Example
Let's say I want to fetch the three top discussions with only their titles, nothing else.
https://discuss.flarum.org/api/discussions?page[size]=3&fields[discussions]=title
The default include adds lots of data. However through selecting the title the relationships are gone and there is no way to manually select them (e.g. ?fields[discussions]=title,relationships won't work, since relationships is not an attribute).
{
"links": {
"first": "https://discuss.flarum.org/api/discussions?page%5Bsize%5D=3&fields%5Bdiscussions%5D=title",
"next": "https://discuss.flarum.org/api/discussions?page%5Bsize%5D=3&page%5Boffset%5D=3&fields%5Bdiscussions%5D=title"
},
"data": [
{
"type": "discussions",
"id": "22974",
"attributes": {
"title": "Dev Diary: Beta 13"
},
// there should be a "relationships": section here
},
{
"type": "discussions",
"id": "22973",
"attributes": {
"title": "Flarum 0.1.0-beta.12 Released"
},
// there should be a "relationships": section here
},
{
"type": "discussions",
"id": "4593",
"attributes": {
"title": "Guidelines for Posting Your Extension"
},
// there should be a "relationships": section here
}
],
"included": [
{
"type": "users",
"id": "1376",
"attributes": {
"username": "luceos",
"displayName": "luceos",
"avatarUrl": "https://discuss.flarum.org/assets/avatars/ZwzFapPty4TcGdYw.png",
"blocksPd": false,
"cannotBeDirectMessaged": false
}
},
{
"type": "users",
"id": "32000",
"attributes": {
"username": "cubixel",
"displayName": "cubixel",
"avatarUrl": "https://discuss.flarum.org/assets/avatars/gIX8PnjWeWhjW4NQ.png",
"blocksPd": false,
"cannotBeDirectMessaged": false
}
},
... // shortened
{
"type": "posts",
"id": "122372",
"attributes": {
"number": 1,
"createdAt": "2020-03-04T10:12:06+00:00",
"contentType": "comment",
"contentHtml": "<p>This is a placeholder, usually you would see some information about our kick off meeting. That meeting is planned for coming Friday, so there's nothing to say to you right now except that Beta 12 just got released.</p>\n\n<p>Feel free to use the Follow button to get notified whenever we talk about development of the upcoming Beta 13 release.</p>\n\n<p>Seeing how well we did with our last release, let's be naughty again by mentioning we target the release of beta 13 for early May 2020 🥳</p> "
}
},
... // shortened
{
"type": "tags",
"id": "16",
"attributes": {
"name": "Meta",
"description": "Discussion about this community: its organisation and how we can improve it.",
"slug": "meta",
"color": "#EF564F",
"backgroundUrl": null,
"backgroundMode": null,
"icon": "fas fa-bullhorn",
"discussionCount": 359,
"position": 5,
"defaultSort": null,
"isChild": false,
"isHidden": false,
"lastPostedAt": "2020-04-28T12:12:24+00:00",
"canStartDiscussion": false,
"canAddToDiscussion": false,
"subscription": null
}
},
... // shortened
]
}
I guess the default inclusions was a conscious decision?
I guess the omitted relationships when specifying fields is a bug?
If you would rather discuss this on GitHub, let me know, I will try to find time to open an issue there..
Best, Simon