docs icon indicating copy to clipboard operation
docs copied to clipboard

Adds an example of modifying items by listening to the POST_READ event

Open yaffol opened this issue 7 years ago • 3 comments

I was trying to modify an API response to add a dynamically generated image URL to any Image items returned from the API. I tried to modify the example BookSubscriber to do this, but struggled to find out how to obtain the item(s) that would be returned by the API from a read request. @TimoBakx helped me out, and this PR adds an example of how to do this.

yaffol avatar Oct 16 '18 09:10 yaffol

Hi, and thanks for contributing to improve the docs, this kind of changes are very appreciated. As for #622, don't you think a normalizer decorator would be a better place to this? Then the code will not be coupled to the HTTP layer anymore, and will be reusable, for instance if you want to send the document to a worker using the Messenger component, or to another internal service using Kafka or a RabbitMQ bus. WDYT?

dunglas avatar Nov 05 '18 08:11 dunglas

Thanks for the feedback. As to #622 @TimoBakx would have to answer that.

yaffol avatar Mar 25 '19 10:03 yaffol

I agree with @dunglas on this. A decorator would work better for most cases. The only case in which a POST_READ listener would be a better option is if you need the data during other parts of handling the request (other listeners further down the line or a controller in case of a custom action). In which case, the question is if you shouldn't put the logic in that spot in the first place.

That being said, I have yet to rewrite and test my part of it to use the decorator instead of a listener.

TimoBakx avatar Mar 25 '19 10:03 TimoBakx