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
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
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
-
API resource existence constraint: Help you to ensure that the related resources are existing on the other microservice when doing validation.
-
Resource collection and pagination: Handy objects and services to ease paginated collection iteration.
-
HTTP repository: An extendable HTTP repository that you could configure to fetch resources.
-
HTTP client wrappers: Clients that adapt HTTP calls according to the targeted microservice configuration.
-
Authentication header providers: Providers that dynamically inject authentication headers in requests.
-
ConstraintViolation list denormalizer: Allows you to create a
ConstraintViolationList
instance from a serialized string. -
Extension points: Events that you can listen to extend the bundle behavior.
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>