composer require bigz/halapibundle
config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
Bigz\HalapiBundle\BigzHalapiBundle::class => ['all' => true],
JmsSerializer.use Symfony\Component\HttpFoundation\Response;
public function showAction($id)
{
$entity = $this->getDoctrine()->getRepository(Entity::class)->find($id);
return new Response($entity); // Serialized with HAL links
}
config/packages/bigz_halapi.yaml (if auto-generated) or app/config/config.yml for overrides.Bigz\HalapiBundle\Serializer\HalapiSerializer if custom metadata is needed.Automatic HAL Injection:
JmsSerializer to append _links to serialized responses.{
"id": 1,
"name": "Test",
"_links": {
"self": { "href": "/api/entities/1" }
}
}
JSON:API Mode (Experimental):
Content-Type: application/vnd.api+json header to transform output to JSON:API format.Custom Link Providers:
Bigz\HalapiBundle\LinkProvider\LinkProviderInterface to add dynamic links (e.g., admin actions).# config/services.yaml
services:
App\LinkProvider\CustomLinkProvider:
tags: ['bigz_halapi.link_provider']
@Halapi\Link annotations (from BigZ/Halapi) on entity properties to define links:
use BigZ\HalapiBundle\Annotation\Link;
/**
* @Link("self", route="entity_show", parameters={"id"="id"})
*/
private $id;
bigz_halapi.pre_serialization to modify HAL data before output:
$eventDispatcher->addListener(
'bigz_halapi.pre_serialization',
function ($event) {
$event->getData()->addLink('custom', '/custom-path');
}
);
api_platform.metadata.extractor services).Deprecated Bundle:
jms/serializer-bundle, symfony/framework-bundle).JSON:API Limitations:
api for production JSON:API needs.Link Provider Conflicts:
tags: ['bigz_halapi.link_provider', { priority: 100 }]
Caching Issues:
JMS_SERIALIZER_DEBUG in .env to inspect serialization groups/metadata.$eventDispatcher->addListener('bigz_halapi.post_serialization', function ($event) {
error_log(print_r($event->getData()->getLinks(), true));
});
Custom Serializers:
serializer service:
bigz_halapi:
serializer: app.custom_serializer
Bigz\HalapiBundle\Serializer\HalapiSerializerInterface.Dynamic Link Generation:
bigz_halapi.link_provider events to inject links conditionally:
$event->getData()->addLinkIf(
'edit',
'/edit',
fn ($entity) => $entity->isEditable()
);
Configuration Overrides:
config/packages/bigz_halapi.yaml:
bigz_halapi:
default_links:
self: { route: "api_entity", parameters: { id: "id" } }
How can I help you explore Laravel packages today?