Guides
Tutorials
§ This class represents an API resource
namespace App\ApiResource;namespace App\ApiResource;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Validator\Exception\ValidationException;use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Validator\Exception\ValidationException;#[ApiResource(
operations: [
new Get(uriTemplate: '/books/{id}'),#[ApiResource(
operations: [
new Get(uriTemplate: '/books/{id}'), new GetCollection(uriTemplate: '/books'),
new Post(uriTemplate: '/books'),
new Patch(uriTemplate: '/books/{id}'),
new Delete(uriTemplate: '/books/{id}'),
], new GetCollection(uriTemplate: '/books'),
new Post(uriTemplate: '/books'),
new Patch(uriTemplate: '/books/{id}'),
new Delete(uriTemplate: '/books/{id}'),
],This is a configuration that is shared accross every operations. More details are available at ApiResource::exceptionToStatus.
exceptionToStatus: [
ValidationException::class => 422
]
)] exceptionToStatus: [
ValidationException::class => 422
]
)]class Book
{
public string $id;
}class Book
{
public string $id;
}Select the next example to see how to hook a persistence layer.