mtarld/api-platform-ms-bundle

API Platform 微服务包

安装次数: 24,355

依赖项: 0

建议者: 0

安全性: 0

星级: 66

关注者: 3

分支: 8

开放问题: 2

类型:symfony-bundle

v1.0.0 2023-04-05 15:07 UTC

This package is auto-updated.

Last update: 2024-09-05 16:38:54 UTC


README

Packagist GitHub Actions Status

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.yamlconfig/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 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>