Can I use the JSON API instead of building a plugin?

I’m pursuing some customizations (such as described here and here) that seem to require a solid understanding of Ember and Rails and also how the underlying Discourse codebase fits together.

As a result, it’s been slow going (I’m more used to Angular and Javascript, and new to Discourse), so I’m looking for ways to get these customizations out the door faster.

So, here’s the question: instead of creating a plugin that manipulates Discourse templates, could I accomplish the same end result using the JSON API?

Having a solid grasp of the API seems more efficient than a solid grasp of Ember and the Discourse codebase, and could be implemented using languages like pure javascript or jquery.

I think the answer is yes. As the team has said, anything that discourse does can be done with the API.

I assume this can work, but the reason for the question: the normal use case for the JSON API, I assume, is a separate app that wants to interact with the Discourse app. In my case, it would be the Discourse app calling its own api.

For example, I had asked before about retrieving and showing the group owners of each group on the group index page. Normally, you would build a plugin for that.

In my case, I would do something like–in my customize dashboard under “<head”–call an AJAX function when the group index page loads that sends an API call to return the group owners of each group, and then inserts that info in each group listing.

Would that work? Would I need to generate an API key for that given that it’s coming from that app itself?

2 Likes

The problem is that if you want to store a new kind of data, you need a plugin. The server needs to know where to store the data, what format is acceptable, who’s allowed to see the data, and who’s allowed to change the data.


Group owner identities are publicly available, so a Theme Component could load them up and display them on the groups index page - slowly.

For category featured topics, there are actually some themes and plugins that use tags to implement that. Have you taken a look at those?

5 Likes

Cool. I probably wouldn’t be looking to store a new kind of data. Rather, I would be dealing with custom fields, following the pre-existing custom field format.

I hadn’t seen plugins for featuring topics on categories previously. The key for me is giving the moderators of the categories the ability to select those. I will take a look.

Regarding using the api for displaying category owners, and displaying other information that I would be getting back from the API: It would make sense if it’s a bit slower than the normal build process, but I’d hope that this method would not be too slow (I’d think it would work just sites that normally retrieve info from apis to fill data).

1 Like

You can only declare new custom fields (and serialize them) in a plugin

2 Likes