Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(content-negociation): document how to declare an encoder for custom format #1797

Open
wants to merge 1 commit into
base: 3.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/content-negotiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ api_platform:
myformat: ['application/vnd.myformat']
```

You will also need to declare an encoder which supports the new format:
nikophil marked this conversation as resolved.
Show resolved Hide resolved

```yaml
nikophil marked this conversation as resolved.
Show resolved Hide resolved
services:
app.api-platform.myformat.encoder:
class: ApiPlatform\Serializer\JsonEncoder
arguments:
$format: 'myformat'
# The following lines are only needed if autoconfigure is disabled
# tags:
# - { name: 'serializer.encoder' }
```

API Platform will automatically call the serializer with your defined format name as `format` parameter during the deserialization process (`myformat` in the example).
It will then return the result to the client with the requested MIME type using its built-in responder.
For non-standard formats, [a vendor, vanity or unregistered MIME type should be used](https://en.wikipedia.org/wiki/Media_type#Vendor_tree).
Expand Down