sroze/api-platform-messenger

There is no license information available for the latest version (dev-master) of this package.

Installs: 103

Dependents: 0

Suggesters: 0

Security: 0

Stars: 31

Watchers: 6

Forks: 2

Open Issues: 1

Type:symfony-bundle

dev-master 2018-08-28 16:31 UTC

This package is auto-updated.

Last update: 2024-10-29 04:59:28 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

  1. 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
  2. Install this bridge

    composer req sroze/api-platform-messenger:dev-master
  3. 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 a GET method
    • command: Will be exposed via a POST method