@@ -87,7 +87,67 @@ In the example above, `xml` or `jsonld` will be allowed and there is no need to
87
87
Additionally the `csv` format is added with the mime type `text/csv`.
88
88
89
89
It is also important to notice that the usage of this attribute will override the formats defined in the configuration, therefore
90
- this configuration might disable the `json` or the `htlm` on this resource for example.
90
+ this configuration might disable the `json` or the `html` on this resource for example.
91
+
92
+ You can specify different accepted formats at operation level too :
93
+ ` ` ` php
94
+ <?php
95
+ // api/src/Entity/Book.php
96
+
97
+ namespace App\E ntity;
98
+
99
+ /**
100
+ * @ApiResource(
101
+ * collectionOperations={"get"={"formats"={"xml"={"text/xml"}}}},
102
+ * attributes={"formats"={"jsonld", "csv"={"text/csv"}}}
103
+ * )
104
+ */
105
+ class Book
106
+ {
107
+ // ...
108
+ }
109
+ ` ` `
110
+
111
+ As an alternative to annotations, you can also use XML or YAML, the example above would become :
112
+
113
+ XML :
114
+ ` ` ` xml
115
+ <resources xmlns="https://api-platform.com/schema/metadata"
116
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
117
+ xsi:schemaLocation="https://api-platform.com/schema/metadata
118
+ https://api-platform.com/schema/metadata/metadata-2.0.xsd">
119
+ <resource class="App\E ntity\G reeting">
120
+ <collectionOperations>
121
+ <collectionOperation name="get">
122
+ <attribute name="formats">
123
+ <attribute name="xml">
124
+ <attribute>text/xml</attribute>
125
+ </attribute>
126
+ <!-- works also with <attribute name="xml">text/xml</attribute> -->
127
+ </attribute>
128
+ </collectionOperation>
129
+ </collectionOperations>
130
+
131
+ <attribute name="formats">
132
+ <attribute>jsonld</attribute> <!-- format already defined in the config -->
133
+ <attribute name="csv">text/csv</attribute>
134
+ </attribute>
135
+ </resource>
136
+ </resources>
137
+ ` ` `
138
+ YAML :
139
+ ` ` ` yaml
140
+ resources:
141
+ App\E ntity\B ook:
142
+ collectionOperations:
143
+ get:
144
+ formats:
145
+ xml: ['text/xml'] # works also with "text/html"
146
+ attributes:
147
+ formats:
148
+ 0: 'jsonld' # format already defined in the config
149
+ csv: 'text/csv'
150
+ ` ` `
91
151
92
152
# # Registering a Custom Serializer
93
153
0 commit comments