Skip to main content

GET Collection Endpoint for Subresources

src/ApiResource/User/ReviewDto.php
namespace App\ApiResource\User;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use App\ApiState\User\Review\BookReviewCollectionProvider;

#[ApiResource(
shortName: 'User/Review',
routePrefix: '/user',
operations: [
// ...
new GetCollection(
uriTemplate: '/books/{bookId}/reviews',
uriVariables: [
'bookId' => new Link(
fromClass: BookDto::class,
),
],
provider: BookReviewCollectionProvider::class,
paginationItemsPerPage: 10
),
// ...
]
)]
class ReviewDto
{
// ...
}