Skip to content

[Idea] Add format by resource #1778

Closed
Closed
@vincentchalamon

Description

@vincentchalamon

Currently, default supported formats are jsonld, json & html. If I want to add a new format, I must add it to api_platform configuration as following:

api_platform:
    formats:
        # ...
        pdf:
            mime_types: ['...']

But this format will be available for all entry-points of my API. I may want to use this format just for some entry-points.

It should be very useful to add a format option directly in the ApiResource annotation, which could be overriden by operation. For instance:

/**
 * @ApiResource(attributes={
 *     "formats"={"jsonld", "json", "html", "csv"={"mime_types"={"text/csv"}}}
 * }, itemOperations={
 *     "put", "delete",
 *     "get"={"formats"={"jsonld", "json", "html", "pdf"={"mime_types"={"application/pdf"}}}}
 * })
 */
class Foo

In this example, csv format is available in all operations except getItem, and this one has pdf format. Those extra formats are only available in this ApiResource.

What do you think of this idea @api-platform/core-team?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions