prsw / typeapi-bundle
TypeApi Impelementation For Symfony
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- psx/api: ^7.1
- symfony/framework-bundle: ^6.4|^7.0
- symfony/serializer: ^7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.3
This package is auto-updated.
Last update: 2024-10-29 13:40:02 UTC
README
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require prsw/typeapi-bundle
Applications that don't use Symfony Flex
Step 1: Download the 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
Step 2: Enable the 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], ];
Usage
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