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!
-
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; }
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