Skip to content

Input/Output Class Semantics #2488

Closed
Closed
@ragboyjr

Description

@ragboyjr

I'd like to just discuss the overall feature of input/output classes and how they relate to API Platform as a whole. I feel like there are a few blind spots that should be considered and documented accordingly.

Should Input Classes always be ApiP Resources?

I think it should be a hard requirement that Input classes should be marked as Resources since it can cause issues/inconsistencies if not.

  1. Only Resources can use the AbstractItemNormalizer

    If input classes aren't resources, you lose the ability to denormalize other relationship objects from IRI string values.

    e.g.

    // example input class
    class CreateBookRequest {
        private $name;
        private $author;
        public function __construct(string $name, Author $author) {
            //
        }
    }

    Input Data

    {
        "name": "Book 1",
        "author": "/authors/1"
    }

    This ONLY works if the input class is also a resource because the AbstractItemNormalizer adds this functionality and it only supports ApiP Resources.

  2. Only Resources can use messenger=true flag

  3. If it's a resource, then we can use the input class resource shortname when building documentation instead of the md5 of its class name. See More Descriptive Input/Output class names #2487

Are Input Classes Useful outside of Messenger Integration?

Input classes make CQRS a lot easier to achieve within ApiP. You can easily create custom write services while keeping ApiP's defaults for reading which is a best of both world's type of situation. With messenger, you can create a service/command handler that handles the request dto and interact with the domain and create the necessary resource.

This type of service wouldn't be coupled to the framework and usable throughout your system. However, to do the same without Messenger, you'd need to create a Data Persister which feels very framework specific and can be especially odd when you don't ever need to implement the remove method of the data persister.

Considering that you can use messenger as a command bus and don't need any external deps like redis/amqp for it to work, it seems like messenger and input classes should be the defacto way for using input classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions