If the amount of data is not too much, the easiest is to add it to the ForumSerializer
, through the ApiSerializer::attributes
extender. This data will be available globally on every page of Flarum through the app.forum
object.
If there is a lot of data and it varies for each page, this will need some more consideration. Is the data unique for each discussion? If so you could add it as attributes on the discussion object through DiscussionSerializer
.
Unless you need the data to be available on the first render of the Mithril single page app, doing a second API query is not necessarily a bad solution. If it's a lot of data and is not critical for the first render, a dedicated asynchronous request might even be better. If the component that shows that data is not in view at the top of the page, you can even delay the request until the component becomes visible in the viewport to reduce the amount of network traffic.