@@ -115,7 +115,7 @@ just by specifying the enabled HTTP method.
115
115
The URL, the HTTP method and the Hydra context passed to documentation generators of operations is easy to configure.
116
116
117
117
In the next example, both ` GET ` and ` PUT ` operations are registered with custom URLs. Those will override the default generated
118
- URLs. In addition to that, we replace the Hydra context for the ` PUT ` operation.
118
+ URLs. In addition to that, we replace the Hydra context for the ` PUT ` operation, and require the ` id ` parameter to be an integer .
119
119
120
120
<configurations >
121
121
@@ -128,8 +128,8 @@ use ApiPlatform\Core\Annotation\ApiResource;
128
128
129
129
/**
130
130
* @ApiResource(itemOperations={
131
- * "get"={"method"="GET", "path"="/grimoire/{id}"},
132
- * "put"={"method"="PUT", "path"="/grimoire/{id}/update", "hydra_context"={"foo"="bar"},
131
+ * "get"={"method"="GET", "path"="/grimoire/{id}", "requirements"={"id"="\d+"} },
132
+ * "put"={"method"="PUT", "path"="/grimoire/{id}/update", "hydra_context"={"foo"="bar"}} ,
133
133
* })
134
134
*/
135
135
class Book
@@ -146,10 +146,14 @@ AppBundle\Entity\Book:
146
146
get :
147
147
method : ' GET'
148
148
path : ' /grimoire/{id}'
149
+ requirements :
150
+ id : ' \d+'
149
151
put :
150
152
method : ' PUT'
151
153
path : ' /grimoire/{id}/update'
152
154
hydra_context : { foo: 'bar' }
155
+ requirements :
156
+ id : ' \d+'
153
157
` ` `
154
158
155
159
` ` ` xml
@@ -165,13 +169,19 @@ AppBundle\Entity\Book:
165
169
<itemOperation name="get">
166
170
<attribute name="method">GET</attribute>
167
171
<attribute name="path">/grimoire/{id}</attribute>
172
+ <attribute name="requirements">
173
+ <attribute name="id">\d+</attribute>
174
+ </attribute>
168
175
</itemOperation>
169
176
<itemOperation name="put">
170
177
<attribute name="method">PUT</attribute>
171
178
<attribute name="path">/grimoire/{id}/update</attribute>
172
179
<attribute name="hydra_context">
173
180
<attribute name="foo">bar</attribute>
174
181
</attribute>
182
+ <attribute name="requirements">
183
+ <attribute name="id">\d+</attribute>
184
+ </attribute>
175
185
</itemOperation>
176
186
</itemOperations>
177
187
</resource>
@@ -486,7 +496,7 @@ In this case, the entity will pass through [all built-in event listeners](events
486
496
automatically validated, persisted and serialized in JSON-LD. Then the Symfony kernel will send the resulting document to
487
497
the client.
488
498
489
- Alternatively, you can also use standard Symfony controller and YAML or XML route declarations. The following example do
499
+ Alternatively, you can also use standard Symfony controller and YAML or XML route declarations. The following example does
490
500
exactly the same thing than the previous example in a more Symfony-like fashion:
491
501
492
502
``` php
0 commit comments