prsw/typeapi-bundle
Composer 安装命令:
composer require prsw/typeapi-bundle
包简介
TypeApi Impelementation For Symfony
README 文档
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
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-29