mtarld/api-platform-ms-bundle

API Platform Microservice Bundle

Installs: 24 373

Dependents: 0

Suggesters: 0

Security: 0

Stars: 66

Watchers: 3

Forks: 8

Open Issues: 2

Type:symfony-bundle

v1.1.0 2023-07-05 14:09 UTC

This package is auto-updated.

Last update: 2024-12-16 15:39:10 UTC


README

Packagist GitHub Actions Status

A Microservice tools bundle for API Platform.

A microservice bundle ?

In a microservice context where each microservices are API Platform instances, each instance must behave as an API Platform data producer and an API Platform data consumer.

But API Platform isn't intended to behave like a client.

Therefore, here comes the API Platform Microservice Bundle!

This bundle intents to provide a set of tools to ease the development of client behaving microservices by trying to abstract the http call layer.

Getting started

Installation

You can easily install API Platform Microservice bundle by composer

$ composer require mtarld/api-platform-ms-bundle

Then, bundle should be registered. Just verify that config\bundles.php is containing :

Mtarld\ApiPlatformMsBundle\ApiPlatformMsBundle::class => ['all' => true],

Configuration

Once the bundle is installed, you should configure it to fit your needs.

To do so, edit config/packages/api_platform_ms.yaml and 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

And you're ready to go ! 🚀

Provided tools

Supported microservice formats

Currently, API Platform supported formats are:

  • jsonld
  • jsonapi
  • jsonhal

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

After writing your fix/feature, you can run following commands to make sure that everything is still ok.

# Install dev dependencies
$ composer install

# Running tests locally
$ make test

Authors

  • Mathias Arlaud - mtarld - <mathias(dot)arlaud@gmail(dot)com>