rekalogika / api-lite
A set of tools to simplify working with API Platform in your projects. Comes with guides, patterns, and practical examples for building API Platform-based projects.
Fund package maintenance!
priyadi
Installs: 1 011
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.2
- api-platform/core: ^3.2.12 || ^3.3 || ^4.0
- doctrine/collections: ^2.2
- rekalogika/mapper: ^1.13.3 || ^1.14
- rekalogika/rekapager-api-platform: ^0.19
- rekalogika/rekapager-doctrine-collections-adapter: ^0.19
- rekalogika/rekapager-doctrine-orm-adapter: ^0.19
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
- symfony/security-core: ^6.4 || ^7.0
- symfony/service-contracts: ^3.4
Requires (Dev)
- composer-runtime-api: ^2.2
- bnf/phpstan-psr-container: ^1.0
- composer/semver: ^3.4
- doctrine/doctrine-bundle: ^2.12
- doctrine/doctrine-fixtures-bundle: ^3.5
- doctrine/orm: ^2.14 || ^3.0
- doctrine/persistence: ^3.1
- ekino/phpstan-banned-code: ^2.1
- fakerphp/faker: ^1.23
- pagerfanta/core: ^4.3
- phpstan/phpstan: ^1.12
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19.0
- rekalogika/doctrine-collections-decorator: ^2.2
- symfony/asset: ^6.4 || ^7.0
- symfony/browser-kit: ^6.4 || ^7.0
- symfony/debug-bundle: ^6.4 || ^7.0
- symfony/doctrine-bridge: ^6.4 || ^7.0
- symfony/event-dispatcher: ^6.4 || ^7.0
- symfony/expression-language: ^6.4 || ^7.0
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/http-client: ^6.4 || ^7.0
- symfony/maker-bundle: ^1.55
- symfony/property-access: ^6.4.4 || ^7.0.4 || ^7.1
- symfony/property-info: 6.4.0 - 6.4.8 || 7.0.0 - 7.0.8 || 7.1.0 - 7.1.1 || ^7.2
- symfony/routing: ^6.4 || ^7.0
- symfony/runtime: ^6.4 || ^7.0
- symfony/security-bundle: ^6.4 || ^7.0
- symfony/serializer: ^6.4.2 || ^7.0.2 || ^7.1
- symfony/twig-bundle: ^6.4 || ^7.0
- symfony/uid: ^6.4 || ^7.0
- symfony/validator: ^6.4 || ^7.0
- symfony/var-dumper: ^6.4 || ^7.0
- symfony/var-exporter: ^6.4.4 || ^7.0.4 || ^7.1
- symfony/web-profiler-bundle: ^6.4 || ^7.0
- symfony/yaml: ^6.4 || ^7.0
- twig/twig: ^3.8
- vimeo/psalm: ^5.26
- zenstruck/foundry: 1.37.*
README
A set of tools to simplify working with API Platform in your projects. Comes with guides, patterns, and practical examples for building API Platform-based projects.
Apply existing knowledge, experience, and patterns of working with Symfony controllers to API Platform state providers and processors. Decouple your persistence layer from the API frontend layer. Apply Domain-Driven Design (DDD) principles to your API Platform-based projects, as well as other architectural patterns and best practices, including SOLID, onion architecture, clean architecture, hexagonal architecture, and others.
'Lite' means we are refraining from using all of API Platform's features and automations in favor of better readability, simplicity, and flexibility.
Full documentation is available at rekalogika.dev/api-lite.
Motivation
API Platform documentation encourages developers to use plain old PHP objects (POPOs) or data transfer objects (DTOs) as the models for API communication, instead of using domain entities directly for this purpose. But it does not establish a practical working patterns for that approach.
Practically all the examples and demos we find on the Internet still
attach ApiResource
to Doctrine entities.
Sometimes API Platform can feel very rigid. It can be difficult to figure out how to accomplish things outside its conventions. There are ways around any problem, just not always immediately obvious. It can feel like that we just want to express what we need by writing a PHP code, not by figuring out the correct combination of attributes to use.
Those coming from Symfony controllers might find API Platform's approach very different, but it does not have to be.
Installation
composer require rekalogika/api-lite
Synopsis
use Doctrine\Common\Collections\Collection; use Rekalogika\ApiLite\State\AbstractProvider; use Rekalogika\Mapper\CollectionInterface; #[ApiResource( shortName: 'Book', operations: [ new Get( uriTemplate: '/books/{id}', provider: BookProvider::class ), ] )] class BookDto { public ?Uuid $id = null; public ?string $title = null; public ?string $description = null; /** * @var ?CollectionInterface<int,ReviewDto> */ public ?CollectionInterface $reviews = null; } /** * @extends AbstractProvider<BookDto> */ class BookProvider extends AbstractProvider { public function __construct( private BookRepository $bookRepository ) { } public function provide( Operation $operation, array $uriVariables = [], array $context = [] ): object|array|null { $book = $this->bookRepository ->find($uriVariables['id'] ?? null) ?? throw new NotFoundException('Book not found'); $this->denyAccessUnlessGranted('view', $book); return $this->map($book, BookDto::class); } }
To-Do List
- Figure out & implement filtering.
Documentation
License
MIT