terminal42/rokka-io-api-platform-bridge
A bridge that connects Rokka.io’s image CDN with API Platform, helping expose optimized Rokka image URLs in your API resources. It streamlines integrating Rokka image stacks and transformations into API Platform-powered applications.
This package is a bridge between Rokka.io (an image processing/CDN service) and API Platform: it lets you expose Rokka-rendered image URLs directly on your API resources instead of hand-building URLs or storing derived image paths. Release 1.1.0 is a compatibility release only — PHP 8.*, Symfony 5 and 6 — so treat it as "same feature set, modern runtime floor."
Prerequisites before you install:
api-platform/core 2.6+ / 3.xteaser, hero)Minimal steps:
composer require terminal42/rokka-io-api-platform-bridgeorganization and api_key, sourced from env (ROKKA_ORGANIZATION, ROKKA_API_KEY). Never hardcode.DependencyInjection/Configuration.php to see the exact config keys, then the service definition that constructs the rokka/client instance, then the attribute/annotation + normalizer that turns a resource property into a URL. The README and src/ are small — read them end to end before writing code.coverImage hash column to an Article resource, annotate the property with a stack name, and confirm GET /articles/{id} returns a Rokka CDN URL instead of a raw hash.If you are on Laravel: this is where you stop and check scope. API Platform's Laravel integration exists, but this bridge exposes Symfony DI services. You will be wiring it manually in a service provider (see Gotchas) — budget an afternoon, not five minutes.
Config-first, stacks as named constants. Keep stack names in config or a PHP enum, not as string literals sprinkled across resources. Stack definitions are the thing most likely to change (dimensions, formats, quality), and a rename should be a one-line config diff.
Store hashes, render URLs. Persist only the Rokka image hash (plus, if you care about reproducibility, the original source hash and upload metadata) on your model. Let the bridge derive the URL at serialization time. This means changing a stack's options or moving to a different stack is a config change, not a data migration. It also sidesteps the classic trap of storing absolute CDN URLs in the database.
Stack-per-context via serialization groups. Map thumb / teaser / hero stacks to different API Platform serialization groups so list endpoints return small renditions and detail endpoints return large ones. URLs are derived from stored hashes, so exposing image fields on collection endpoints is essentially free — no N+1, no extra queries.
Uploads are your job, rendering is the bridge's. Handle the multipart upload in your own API Platform operation (a custom POST/PUT controller), push the binary through the Rokka client, persist the returned hash, and let the bridge handle representation only. Don't try to make the bridge a media library.
Fake the client in tests. Bind a stub to the Rokka client interface in your test container so feature tests never touch the network. Assert on URL shape (host, stack segment, hash) rather than an exact string — Rokka URLs include stack config that will drift.
Cache hard. Rokka URLs are content-addressed by hash + stack configuration. A stack edit produces new URLs, so long-lived Cache-Control headers and CDN caching are safe and are where most of the perceived performance win comes from.
Decorate, don't fork. The URL-rendering service and the normalizer are the two sensible override points. If you need custom stack parameters per request (e.g. responsive variants), decorate the renderer rather than editing vendor code.
config/rokka.php to publish. Under api-platform/laravel you must register the bundle's services manually or wrap it in a thin provider. The 1.1.0 constraint (Symfony 5/6) also means you inherit whatever Symfony components API Platform's Laravel package pulls in — run composer why symfony/http-kernel and confirm there's no conflict before committing to this.TypeError. Audit nullable properties on your resources and anything you pass into the Rokka client.source_hash column and, if you need reproducibility, an upload history table.normalization_context first, every time.^1.1 is reasonable. There's no 2.x line and the surface area is small, so be prepared to vendor-patch or decorate if you need behaviour the bridge doesn't offer; don't expect frequent releases.How can I help you explore Laravel packages today?