Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
$ composer require prsw/typeapi-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require prsw/typeapi-bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
PRSW\TypeApiBundle\TypeApiBundle::class => ['all' => true],
];
Add TypeApi routes in config/routes.yml
typeapi:
resource:
path: .
type: typeapi
Now you can use TypeApi attribute to define your API definition in your class, you mush add TypeApi
attribute in your class in order to autoload them in symfony routes.
<?php
declare(strict_types=1);
namespace App\Api;
use App\Dto\Hello;
use App\Dto\Payload;
use PRSW\TypeApiBundle\Attributes\Path;
use PRSW\TypeApiBundle\Attributes\TypeApi;
use PSX\Api\Attribute\Body;
use PSX\Api\Attribute\Post;
#[TypeApi]
final class PostCollection
{
#[Post]
#[Path('/hello')]
public function hello(
#[Body]
Payload $payload
): Hello {
return Hello::create($payload->name, '', $payload->id);
}
}
All is setup to verify route already registered or not you check via ./bin/console debug:router