Summary: API Platform introduced more type hints, which now prevents a workaround for custom responses. Refactoring this is hard, and might require different API nodes.
Some API nodes (like api/issues/report) do not return a json+ld response, but binary data or another custom format. Due to an implementation detail, it was possible to simply return a Response in the DataProvider. However, the DataProvider now enforces [] as a return type, hence this is no longer possible.
We want to continue to use the DataProvider to reuse the logic around the search parameters. However, we now have to convert the result of the DataConverter into a proper Response at another place.
This mechanism was used for all api nodes which return non-doctrine-entites. For Dtos, it is already fixed on this branch. It only required some serialization config; however the API format slightly changes: As now API Platform does the serialization, the response is in the hydra format. This PR is therefore already a breaking change!
Three special cases exist, with each needing their own workaround:
/api/issues/summary returns a single object instead of a list
/api/issues/render.jpg returns an image instead of text
/api/issues/report returns a PDF link instead of issues
The current approach uses custom encoders for each of these three nodes. However, this has two problems:
The custom encoders are called on every serialization procedure, which slows down the application.
The custom encorders' output is forced to be string; hence directly returning binary is not possible.
Two ways forward:
Continue with the serialization approach, and change the render API to return an URL (so its text again). Dirty, but will work.
Disable serialization, and hook directly into the event system to generate the response. Cleaner, but so far unclear how this can be done.
Summary: API Platform introduced more type hints, which now prevents a workaround for custom responses. Refactoring this is hard, and might require different API nodes.
Some API nodes (like
api/issues/report
) do not return a json+ld response, but binary data or another custom format. Due to an implementation detail, it was possible to simply return aResponse
in theDataProvider
. However, theDataProvider
now enforces[]
as a return type, hence this is no longer possible.We want to continue to use the
DataProvider
to reuse the logic around the search parameters. However, we now have to convert the result of the DataConverter into a properResponse
at another place.This mechanism was used for all api nodes which return non-doctrine-entites. For Dtos, it is already fixed on this branch. It only required some serialization config; however the API format slightly changes: As now API Platform does the serialization, the response is in the hydra format. This PR is therefore already a breaking change!
Three special cases exist, with each needing their own workaround:
/api/issues/summary
returns a single object instead of a list/api/issues/render.jpg
returns an image instead of text/api/issues/report
returns a PDF link instead of issuesThe current approach uses custom encoders for each of these three nodes. However, this has two problems:
Two ways forward: