violines/rest-bundle
Composer 安装命令:
composer require violines/rest-bundle
包简介
violines/rest-bundle is a Symfony Bundle to create REST APIs. It focusses on HTTP standards and integrates the symfony/serializer and symfony/validator.
README 文档
README
violines/rest-bundle is a Symfony Bundle to create REST APIs. It focusses on HTTP standards and integrates the symfony/serializer and symfony/validator.
Features
- Request body or query string to object conversion
- Response building from objects
- Configurable content negotiation
- Events to control symfony/serializer context
- Integration of symfony/validator
- Error Handling
- Optional Logging
Compatible with...
- Symfony 5.4 + 6
- PHP 8 + 8.1
Designed for...
modern architectures that apply Domain Driven Design principles, hexagonal architecture or similar concepts.
Install
composer require violines/rest-bundle
How does it work?
- Create any PHP class (Entity, DTO, Command, Query, etc) and add the
#[HttpApi]attribute or@HttpApiannotation - Use any property attributes/annotations from symfony/serializer or symfony/validator
- Declare this PHP class as type of a controller argument
- Return an instance of this PHP class in the controller
Show Case
Find a sample of usage under: https://github.com/violines/rest-bundle-showcase.
Example
<?php declare(strict_types=1); namespace App\Entity; #[Violines\RestBundle\HttpApi\HttpApi] final class Order { public $amount; public $articles; } // Or use Doctrine Annotations (requires separate install): // In order to use Annotations you have to install `doctrine/annotations` via `composer require doctrine/annotations` /** * @Violines\RestBundle\HttpApi\HttpApi */ final class Order {}
<?php declare(strict_types=1); namespace App\Controller; use App\Exception\AuthenticationFailedException; use App\Entity\Order; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class OrderController { /** * @return Order[] */ #[Route('/orders', methods: ['GET'], name: 'find_orders')] public function findOrders(): array { return $this->orderRepository->findOrders(); } #[Route('/order/{id}', methods: ['GET'], name: 'find_order')] public function findOrder(int $id): Order { $order = $this->orderRepository->find($id); if (null === $order) { throw NotFoundException::id($id); } return $order; } /** * @param Order[] $orders */ #[Route('/orders/create', methods: ['POST'], name: 'create_orders')] public function createOrders(Order ...$orders): Response { $this->orderRepository->createOrders($orders); return new Response(null, Response::HTTP_CREATED); } #[Route('/order/create', methods: ['POST'], name: 'create_order')] public function createOrder(Order $order): Response { $this->orderRepository->create($order); return new Response(null, Response::HTTP_CREATED); } }
Wiki
For more details please check violines/rest-bundle Wiki.
Development setup
- copy docker/.env.dist to docker/.env and adjust to your needs
- cd docker/
- pull latest image(s): docker-compose pull
- create the container(s): docker-compose up -d
- run tests with
docker-compose exec php80 composer run test
violines/rest-bundle 适用场景与选型建议
violines/rest-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 203 次下载、GitHub Stars 达 36, 最近一次更新时间为 2020 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 violines/rest-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 violines/rest-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 203
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-08