sroze / api-platform-messenger
Installs: 103
Dependents: 0
Suggesters: 0
Security: 0
Stars: 31
Watchers: 6
Forks: 2
Open Issues: 1
Type:symfony-bundle
Requires
- api-platform/core: ^2.1
- symfony/framework-bundle: ^3.3 || ^4.0
This package is auto-updated.
Last update: 2024-11-29 05:26:53 UTC
README
Using a message bus like Symfony Messenger is a wonderful way of structuring your application around commands or queries (which will just be PHP classes). API Platform is a great framework to expose APIs.
The point of this bridge is to enable you to build business actions-centric APIs instead of CRUD APIs. Check this very simple example.
Note: This is still an experimentation. You will likely have to contribute to make it fit your needs. Looking forward to review your pull-requests!
Usage
-
Get an API Platform application. Easiest is to use Symfony's
api
pack:composer create-project symfony/skeleton api-platform-and-messenger && \ cd api-platform-and-messenger && \ composer req api
-
Install this bridge
composer req sroze/api-platform-messenger:dev-master
-
Configure your message(s) to be handled by API Platform like in the following example:
<?php namespace App\Message; use Sam\ApiPlatform\Messenger\Annotation\ApiMessage; use Symfony\Component\Validator\Constraints\NotBlank; /** * @ApiMessage( * path="/write-message", * type="command" * ) */ class WriteMessage { /** * @NotBlank * * @var string */ public $message; }
Reference
@ApiMessage
annotation
path
. The URL path where your command will be exposed.type
. The type of message. Can be:query
: Will be exposed via aGET
methodcommand
: Will be exposed via aPOST
method