Skip to content

Commit 64d62d1

Browse files
Toflardunglas
authored andcommitted
Docs for the new routePrefix config (#391)
* Docs for the new routePrefix config * Update operations.md
1 parent 52f75b5 commit 64d62d1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core/operations.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ Or in XML:
228228

229229
In all the previous examples, you can safely remove the `method` because the method name always match the operation name.
230230

231+
### Prefixing All Routes of All Operations
232+
233+
Sometimes it's also useful to put a whole resource into its own "namespace" regarding the URI. Let's say you want to
234+
put everything that's related to a `Book` into the `library` so that URIs become `library/book/{id}`. In that case
235+
you don't need to override all the operations to set the path but configure a `routePrefix` for the whole entity instead:
236+
237+
```php
238+
<?php
239+
// api/src/Entity/Book.php
240+
241+
use ApiPlatform\Core\Annotation\ApiResource;
242+
243+
/**
244+
* ...
245+
* @ApiResource("attributes"={"routePrefix"="/library"})
246+
*/
247+
class Book
248+
{
249+
//...
250+
}
251+
```
252+
231253
## Subresources
232254

233255
Since ApiPlatform 2.1, you can declare subresources. A subresource is a collection or an item that belongs to another resource.

0 commit comments

Comments
 (0)