mtarld / api-platform-ms-bundle
API Platform 微服务包
v1.0.0
2023-04-05 15:07 UTC
Requires
- php: ^8.1
- api-platform/core: ^3.0.12
- psr/log: ^1.0|^2.0|^3.0
- symfony/event-dispatcher: ^6.1
- symfony/http-client: ^6.1
- symfony/http-foundation: ^6.1
- symfony/polyfill-php80: ^1.20
- symfony/property-access: ^6.1
- symfony/serializer: ^6.1
- symfony/validator: ^6.1
- symfony/web-link: ^6.1
Requires (Dev)
- doctrine/annotations: ^1.7
- doctrine/inflector: ^2.0
- friendsofphp/php-cs-fixer: ^3.1
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.15
- rector/rector: ^0.15.23
- symfony/browser-kit: ^6.1
- symfony/framework-bundle: ^6.1
- symfony/phpunit-bridge: ^6.1
- symfony/yaml: ^6.1
- vimeo/psalm: ^4.3
- willdurand/negotiation: ^3.0
README
API Platform 微服务工具包。
什么是微服务包?
在微服务环境中,每个微服务都是 API Platform 的实例,每个实例都必须同时作为 API Platform 数据生产者和消费者。
但 API Platform 并不是为客户端设计的。
因此,这就是 API Platform 微服务包的由来!
本包旨在提供一系列 工具,通过抽象 http 调用层来简化客户端行为微服务的开发。
入门指南
安装
您可以通过 composer 轻松安装 API Platform 微服务包
$ composer require mtarld/api-platform-ms-bundle
然后,应该注册包。只需确认 config\bundles.php
中包含
Mtarld\ApiPlatformMsBundle\ApiPlatformMsBundle::class => ['all' => true],
配置
一旦安装了包,您应该根据需要对其进行配置。
为此,编辑 config/packages/api_platform_ms.yaml
和 config/routes/api_platform_ms.yaml
# config/packages/api_platform_ms.yaml api_platform_ms: # HttpClient that will be used internally (default: 'Symfony\Contracts\HttpClient\HttpClientInterface') http_client: ~ # Name of the current microservice (required) name: client # Option to log request (default '%kernel.debug%') log_request: true # Host used for microservice dynamic routes generation (default: []) hosts: - https://client.api # List of related microservices microservices: # Microservice name product: # Microservice base uri (required) base_uri: https://product.api # Microservice API path (default: '') api_path: /api # Microservice format (required) # Supported formats: jsonld, jsonhal, jsonapi format: jsonld
# config/routes/api_platform_ms.yaml api_platform_ms: resource: '@ApiPlatformMsBundle/Resources/config/routes.xml' prefix: /api
然后您就可以出发了!🚀
提供工具
-
API 资源存在约束:帮助您在验证时确保相关资源在其他微服务上存在。
-
资源集合和分页:便于分页集合迭代的实用对象和服务。
-
HTTP 仓库:可配置的扩展 HTTP 仓库,可用来获取资源。
-
HTTP 客户端包装器:根据目标微服务配置调整 HTTP 调用的客户端。
-
认证头提供者:提供者可动态注入请求中的认证头。
-
约束违规列表反序列化器:允许您从一个序列化的字符串中创建
ConstraintViolationList
实例。 -
扩展点:您可以监听的事件,用于扩展包的行为。
支持的微服务格式
目前,API Platform 支持的格式有
- jsonld
- jsonapi
- jsonhal
贡献
请阅读 CONTRIBUTING.md 了解我们的行为准则以及向我们提交拉取请求的流程。
在编写修复/功能后,您可以运行以下命令以确保一切正常。
# Install dev dependencies $ composer install # Running tests locally $ make test
作者
- Mathias Arlaud - mtarld - <mathias(dot)arlaud@gmail(dot)com>