composer create-project symfony/skeleton bookshop-api cd bookshop-api composer require symfony/orm-pack composer require --dev symfony/maker-bundle composer req apifill .env with database infos and then
bin/console doctrine:database:create bin/console make:entity #bin/console doctrine:schema:create bin/console make:migration bin/console doctrine:migrations:migraterun test server
php -S 192.168.0.124:8000 -t publicfrontend available at http://192.168.0.124:8000/api
add title, description and version. in config/packages/api_platform.yaml
api_platform:
title: "toto"
description: "ben voila"
version: "1.0"
mapping:
paths: ['%kernel.project_dir%/src/Entity']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
in entity class header
* @ApiResource(
* collectionOperations={"get"},
* itemOperations={"get", "put", "delete"}
* )
in entity class header
/**
* @ApiResource(
* normalizationContext={"groups"={"article:read"}},
* denormalizationContext={"groups"={"article:write"}}
* )
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
*/
class Article
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*
* @Groups("article:read")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({"article:read", "article:write"})
*/
private $title;