API Platform Configuration
Edit on GitHubSpryker uses API Platform’s configuration options with Spryker-specific adaptations for PHP-based configuration and environment control.
Configuration file locations
Configuration files are located in application-specific directories:
- GlueBackend:
config/GlueBackend/packages/api_platform.php - GlueStorefront:
config/GlueStorefront/packages/api_platform.php - Glue:
config/Glue/packages/api_platform.php
Spryker-specific differences
PHP configuration instead of YAML
Spryker uses PHP configuration with Symfony’s type-safe configuration objects instead of YAML files:
use Symfony\Config\ApiPlatformConfig;
return static function (ApiPlatformConfig $apiPlatform, string $env): void {
// Configuration here
};
Environment variable for conditional settings
The configuration function receives an $env parameter for environment-specific behavior:
return static function (ApiPlatformConfig $apiPlatform, string $env): void {
// Enable developer tools only in development
if ($env === 'dockerdev') {
$apiPlatform->enableSwagger(true);
$apiPlatform->enableSwaggerUi(true);
$apiPlatform->enableReDoc(true);
$apiPlatform->enableDocs(true);
}
};
Common environment values: prod, dev, dockerdev, test
Configuration examples
Disable SwaggerUI in production
Spryker shows the SwaggerUI only in development environments by default. This can be configured with:
if ($env === 'dockerdev') {
$apiPlatform->enableSwagger(true);
$apiPlatform->enableSwaggerUi(true);
$apiPlatform->enableReDoc(true);
$apiPlatform->enableDocs(true);
}
Disable Doctrine integration
Spryker does not use Doctrine with API Platform:
$apiPlatform->doctrine()->enabled(false);
$apiPlatform->doctrineMongodbOdm()->enabled(false);
Configure resource mapping paths
Specify where API Platform discovers resource classes. By default, only the generated resource directory is configured:
$apiPlatform->mapping()->paths([
'%kernel.project_dir%/src/Generated/Api/Backend'
]);
Add custom resource paths
To use native API Platform resources alongside generated resources, add your directories to the mapping paths:
$apiPlatform->mapping()->paths([
'%kernel.project_dir%/src/Generated/Api/Backend',
'%kernel.project_dir%/src/Pyz/Glue/*/Api/Backend/Resource',
]);
API Platform scans all configured paths for PHP classes with #[ApiResource] attributes. Generated and hand-written resources coexist without conflict.
Always keep the src/Generated/Api/{ApiType} path in the list. Removing it disables all YAML-generated resources.
For a complete guide on creating native resources, see Native API Platform Resources.
Set pagination defaults
$apiPlatform->defaults()->paginationItemsPerPage(10);
$apiPlatform->collection()
->pagination()
->pageParameterName('page')
->itemsPerPageParameterName('itemsPerPage');
These global defaults apply to all resources. Individual resources can override pagination behavior using per-resource options such as paginationEnabled, paginationItemsPerPage, paginationMaximumItemsPerPage, paginationClientEnabled, and paginationClientItemsPerPage in their YAML schema files. See Resource Schemas — Pagination for details.
Configure supported formats
$apiPlatform->formats('jsonapi', ['mime_types' => ['application/vnd.api+json']]);
$apiPlatform->formats('jsonld', ['mime_types' => ['application/ld+json']]);
$apiPlatform->formats('xml', ['mime_types' => ['application/xml']]);
Configure security
Security is configured in a separate security.php file. For details, see How to integrate API Platform Security.
Complete configuration reference
For all available configuration options and their details, refer to the API Platform Symfony Configuration documentation.
The PHP method names in ApiPlatformConfig correspond directly to the YAML keys in the official documentation.
Thank you!
For submitting the form