// src/App/ApiResource.php
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Validator\Exception\ValidationException;
#[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}'),
],
exceptionToStatus: [
ValidationException::class => 422,
]
)]
class Book
{
public string $id;
}
// src/App/Playground.php
namespace App\Playground;
use Symfony\Component\HttpFoundation\Request;
function request(): Request
{
return Request::create('/docs', 'GET');
}
Made with love by
Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.
Learn more