Skip to main content

GET Endpoint for a Subresource

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;
use App\ApiState\User\Review\BookReviewProvider;

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