I can see that I can modify a particular response from a controller say the ‘find()’ method and override this to inject additional content into the output for the API endpoint. What I’m interested in doing is parsing the response from any content type’s API response and if certain content is present augmenting that with custom output. I can’t see a neat way of doing this with hooks and I don’t think middleware is what I’m after. Has anyone faced a similar issue and come up with a decent approach?
The use case is: A particular component, let’s say called ‘Most Recent Articles’ can be implemented in a dynamic zone on several different content types of my Strapi app. I basically want to intercept when this component is present for a particular entity, run a query to the get latest three ‘Articles’ and inject this data into the API response when find(), findOne() or search() is used to retrieve a collection of content. I could do this individually per content type, perhaps running the entities retrieved through a custom function, but that’s forcing me to repeat code in each controller. I think a better solution would somehow being able to target the response from these three methods from any controller at a global level and run the response through my custom code to inject the data as required.
I hope this makes sense!