api-platform/core

Mercure : Have the possibility to dispatch events in multiple formats

Xusifob opened this issue · 3 comments

Description
API Platform allows multiple formats to be available together within the API (jsonld, jsonapi, graphql...) however, mercure will only send the SSE events in the 1st format configured within the app.

My proposal is to offer the possibility to enable mercure to push the same event into multiple formats. So, subscribers will be able to listen to only events in json:api or jsonld, and get the data in a format they can process.

Example

  • Configuration :
    Add a new key "mercure_formats" in the API Platform configuration file :
# config/packages/api_platform.yaml
api_platform:
    mercure:
        formats: ['jsonld','jsonapi']

Then, the app will send the event in all the formats, prefixing all routes with the format.

Exemple : for the topic /users/33/discussions, it will send both topics :

  • jsonld/users/33/discussions
  • jsonapi/users/33/discussions

And the subscriber will have the possibility to subscribe to the format it wishes to get.

If needed, I can work on a PR for this issue

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.