rfrommherz / api
Symfony api 简化器
1.0.0
2021-12-29 00:36 UTC
Requires
- php: >=8.0
- doctrine/annotations: ^1.13
- ramsey/uuid: ^4.2
- symfony/serializer: 5.3.*
- symfony/validator: 5.3.*
- symfony/yaml: 5.3.*
This package is auto-updated.
Last update: 2024-09-06 04:09:29 UTC
README
安装
composer req rfrommherz/api- config/bundles.php: 在 bundles.php 中添加新捆绑包
Rf\ApiBundle\JwtBundle::class => ['dev' => true],
使用方法
ApiDto
ApiDto 可以用作控制器中的参数。为了启用对此的支持,您的类必须扩展 ApiDto。每个 ApiDto 都会传递给 symfony 验证器,从而启用对验证注解的支持。
use Rf\ApiBundle\Dto\ApiDto; use Symfony\Component\Validator\Constraints as Assert; class Fetch extends ApiDto { /** * @Assert\NotBlank * @Assert\Url * @var string */ private string $repositoryUrl;
参数将自动解析,并可以作为控制器参数传递。
public function index(Fetch $fetch): Response { ... }
curl --location --request GET 'https:///fetch' \ --header 'Content-Type: application/json' \ --data-raw '{ "repositoryUrl": "http://...", }'