steffenbrem/json-api-bundle
Symfony bundle for building JSON:API-compliant APIs. Define resources and relationships, integrate Doctrine entities, and get filtering, sorting, pagination, includes, sparse fieldsets, links, validation, and standardized error responses out of the box.
vendor:publish. Day-to-day leverage assumes a Symfony 2.8/3.x app (the era of the last release, Feb 2017) with JMS Serializer installed. In a Laravel codebase you are looking at a port or a standalone JMS Serializer setup, not a drop-in.composer require steffenbrem/json-api-bundleapp/AppKernel.php: new SteffenBrem\JsonApiBundle\JsonApiBundle()JMS\SerializerBundle\JMSSerializerBundle is registered and configured.config.yml (check DependencyInjection/Configuration.php for the exact key and options — the tree is small).src/DependencyInjection/Configuration.php — the real documented surface area.src/Resources/config/services.yml — service ids you will inject or override.src/Serializer/ (or equivalent) — the JMS visitor/handler that turns objects into JSON API documents.tests/ — the README is thin-to-nonexistent; tests are the de facto docs.@Serializer\Type/@Groups, inject the bundle's serializer service (or JMS configured with the JSON API format), and return a response with Content-Type: application/vnd.api+json. Verify the shape (data, type, id, attributes) before wiring relationships.bin/console debug:container | grep -i json and bin/console debug:config <root_key> (Symfony 3.2+).JsonResponse subclass that sets application/vnd.api+json.@Groups({"api"}) on exposed fields and serialize with the api group. This separates persistence from representation and avoids leaking Doctrine internals.relationships, and optionally included plus links. JMS serializes nested objects, but the bundle is unlikely to automatically build the included array or links.related. Start with relationships-only for CRUD; add compound documents later via post-processing or a custom handler.data: []. If the bundle exposes pagination config, use it; otherwise add links/meta in a response factory so pagination stays consistent across controllers.data.attributes, data.relationships). Do not bind directly to form requests/entities. Write a small request-to-DTO mapper — most of your app-specific code lives here.{"errors": [...]}. Add an exception listener or controller wrapper that maps validation/HTTP errors into that shape; Symfony's default exception output will violate the spec.Accept for application/vnd.api+json and return 406 for unsupported media types. A kernel event listener is a reasonable home for this.symfony/*, jms/serializer-bundle, and php constraints, and test the exact versions before committing.application/vnd.api+json; Symfony's JsonResponse sends application/json. Set it in one base response class — scattered new JsonResponse() calls are the most common compliance bug.data/type/id/attributes. The bundle bridges simple cases, but included, links, meta, sparse fieldsets (fields[type]), sorting, and pagination params are usually not covered. Budget for a response layer.?include=/?fields=, clients get more than requested. Filter the serialized array against query params before returning.@MaxDepth, explicit groups, and query joins/eager fetching where relationships are exposed.bin/console cache:clear after YAML edits; silent staleness in dev is common.debug:container <service> to find the serializer service id; debug:config for the config tree; a small fixture serialization test to see output without HTTP. Because docs are sparse, the repo's tests are the best reference.Resources/config/services.yml. Prefer compiler passes or service decoration over editing vendor files; the bundle is small enough that copying its serializer/handler into your app is a pragmatic escape hatch when the 2017 code does not fit.How can I help you explore Laravel packages today?