Is there a way to modify Discourse endpoints through plugin?

for example, I want to change the result on /latest.json endpoint,
and I found the controller is list_controller.rb,
is there a way to modify related functions through plugin?

There’s almost nothing a plugin can’t do. The question is generally more: is it a good idea ? is it maintainable?

What have you tried so far ?

A good starting point it to look at our all-the-plugins repo and search for similar patterns.

2 Likes

It’s best to look at an example, I believe you can amend the serialisers:

Consider this:

https://github.com/discourse/discourse/blob/acd1693dac1bff6ff50250d942134bc48a27ff14/app/serializers/topic_list_item_serializer.rb

With, for example, the Topic List Previews Plugin edits, from here:

https://github.com/angusmcleod/discourse-topic-previews/blob/master/serializers/topic_list_item_edits.rb

This appends a load of extra attributes. Try it and take a look.

4 Likes

ok, thank you so much!

1 Like