In API Platform v4, operations are declared using classes from the ApiPlatform\Metadata namespace within the #[ApiResource] attribute.
CRITICAL v4 behavior change: As soon as you manually declare any operation in the operations array, API Platform stops auto-registering the default CRUD routes. You must explicitly declare every operation you want to expose (e.g., Get, Post, Put, etc.).
Default behaviors (when no operations key is provided):
- Item operations:
GET (mandatory), PATCH, DELETE. Note that PUT is never auto-registered. - Collection operations:
GET (mandatory), POST.
Disabling all routes: To expose a model for subrequests or IRIs only without any HTTP routes, pass an empty array to operations.
Note: The v2-era collectionOperations and itemOperations arrays were removed in v3 and are fully gone in v4.
<?php
// src/Entity/Book.php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Delete;
#[ApiResource(
operations: [
new GetCollection(),
new Get(),
new Post(),
new Put(), // PUT is NOT registered automatically — declare it if you need it
new Patch(),
new Delete(),
],
)]
class Book
{
// ...
}