CDN Product Images: Shop API
Shop API/headless behaviour of the Sylius plugin CDN Product Images: context-correct resizing on the API Platform channel too.
CDN Product Images: Shop API
This documentation always describes the latest published version.
Live Demo: Try this and other plugins live — no installation, no risk: demo.markus-michalski.net
Dual-mode
This plugin is dual-mode: CDN image URLs are freshly re-signed per rendering context identically on the Twig storefront/Admin and on the headless Shop API channel (API Platform) - not through a new endpoint, but by decorating the existing image normalizer.
graph LR
A["Storefront/Admin Twig imagine_filter"] --> C["ImgproxyUrlSigner"]
B["Shop API image delivery"] --> C
C --> D["Admin CDN Integration settings"]
D --> E["mm-media-cdn Signing Service"]
E --> F["Twig render"]
E --> G["JSON response"]
Behaviour
- The plugin decorates
sylius_api.normalizer.image- and therefore the image serialization of every existing Shop API endpoint that returns a product or taxon image (e.g. the product and taxon detail endpoints). There is no additional, dedicated endpoint. - The decoration only activates when
SyliusApiBundleis registered in the project - without the Shop API channel, nothing else changes. - The
?imageFilter=...query parameter API Platform already supports decides which Sylius Imagine filter size gets signed for - exactly like a locally uploaded image.
Example
curl "https://shop.example.com/api/v2/shop/products/mug-sw?imageFilter=sylius_shop_product_large_thumbnail"
For a CDN image, the returned image field carries a freshly signed mm-media-cdn URL sized for sylius_shop_product_large_thumbnail instead of the unchanged URL that was entered.
Error format
This plugin introduces no error format of its own: a failed signing attempt (network error, timeout, non-2xx) never produces an API error - it degrades to the unchanged, unsigned URL that was entered. A working (if not optimally sized) image always beats a broken one.