diglin/custom-entity-api-endpoint-bundle
Installation Run:
composer require diglin/custom-entity-api-endpoint-bundle:1.*
Ensure Composer updates composer.json and installs dependencies.
Enable the Bundle
Add to config/bundles.php (Laravel 5.4+) or AppKernel.php (Symfony/Laravel <5.4):
Diglin\Bundle\ApiRefDataBundle\DiglinApiRefDataBundle::class => ['all' => true],
Route Configuration
Add to routes/api.php (Laravel) or routing.yml (Symfony):
diglin_api_ref_data:
resource: "@DiglinApiRefDataBundle/Resources/config/routing.yml"
prefix: /api
For Laravel, ensure the prefix aligns with your API routes (e.g., /api/rest/v1).
First Use Case
Fetch reference data for a custom entity (e.g., color):
GET /api/rest/v1/reference-data/color
Fetch a specific item (e.g., code=RED):
GET /api/rest/v1/reference-data/color/RED
Fetching Reference Data Lists
Use the api_ref_data_reference_data_list endpoint to retrieve all items for a custom entity:
$response = Http::get('/api/rest/v1/reference-data/color');
$data = $response->json();
?page=1&limit=20).?locale=en_US).Fetching Single Items
Use api_ref_data_reference_data_get for specific items:
$response = Http::get('/api/rest/v1/reference-data/color/RED');
$item = $response->json();
Integration with Akeneo
akeneo-labs/custom-entity-bundle is installed and configured.color, size) are defined in Akeneo’s PIM.Laravel-Specific Patterns
class ReferenceDataService {
public function getList(string $referenceName): array {
return Http::get("/api/rest/v1/reference-data/{$referenceName}")->json();
}
}
class ReferenceDataDTO {
public string $code;
public string $label;
// ...
}
Testing
Http client responses for isolated testing.actingAs() to test authenticated requests if Akeneo requires API keys.Routing Conflicts
/api/rest/v1 prefix may clash with existing Laravel API routes.config/packages/diglin_api_ref_data.yaml (if supported) or extend the bundle’s routing:
# config/routes/api.php
diglin_api_ref_data:
resource: "@DiglinApiRefDataBundle/Resources/config/routing.yml"
prefix: /akeneo/api/v1 # Custom prefix
Authentication
Route::middleware(['auth:api'])->group(function () {
// Existing routes...
});
Or configure HTTP client defaults:
Http::macro('akeneo', fn ($url) =>
Http::withHeaders(['Authorization' => 'Bearer ' . config('akeneo.api_token')])->get($url)
);
Custom Entity Not Found
404 when querying non-existent custom entities (e.g., /api/rest/v1/reference-data/invalid).public function isValidReferenceEntity(string $name): bool {
return in_array($name, config('akeneo.custom_entities'));
}
Caching
$cacheKey = "ref_data_{$referenceName}";
return Cache::remember($cacheKey, now()->addHours(1), function () use ($referenceName) {
return Http::get("/api/rest/v1/reference-data/{$referenceName}")->json();
});
Extending Functionality
// src/Controller/ReferenceDataController.php
public function listAction(Request $request, $referenceName) {
$query = $request->query->all();
// Add custom logic (e.g., filter by locale)
return parent::listAction($request, $referenceName);
}
Error Handling
{"error": "Not found"}):
try {
$response = Http::get('/api/rest/v1/reference-data/color/INVALID');
$response->throw();
} catch (HttpException $e) {
if ($e->response->json()['error'] === 'Not found') {
// Custom logic
}
}
Performance
Documentation
/**
* @OA\Get(
* path="/api/rest/v1/reference-data/{referenceName}",
* summary="Get reference data list",
* @OA\Parameter(
* name="referenceName",
* in="path",
* required=true,
* @OA\Schema(type="string")
* )
* )
*/
Bundle Updates
akeneo-labs/custom-entity-bundle or this bundle.How can I help you explore Laravel packages today?