Skip to content

Commit

Permalink
docs(content-negociation): document how to declare an encoder for cus…
Browse files Browse the repository at this point in the history
…tom format
  • Loading branch information
nikophil committed Sep 14, 2023
1 parent 07dd615 commit 8dea009
Showing 1 changed file with 13 additions and 0 deletions.
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:

```yaml
services:
app.api-platform.myformat.encoder:
class: ApiPlatform\Serializer\JsonEncoder
argumments:
$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

0 comments on commit 8dea009

Please sign in to comment.