FOSRestBundle
Symfony bundle that turns controllers into format-agnostic REST endpoints with content negotiation and view layer
Repository Health
Technical Analysis
FOSRestBundle is the long-standing Symfony bundle for building RESTful APIs, adding a View layer that decouples controller return values from the final HTTP response format, Accept-header-based content negotiation, structured request-body decoding, and configurable mapping of exceptions to HTTP status codes. It has been the de facto way to build JSON/XML APIs on Symfony since the framework’s early versions, predating and still coexisting with Symfony’s newer built-in Serializer-based API tooling.
Beyond response formatting, the bundle wires in RFC 7807-compliant problem-details error rendering (via Symfony Serializer or JMSSerializer), route-based versioning, and parameter-fetching helpers, making it a full toolkit for teams that want conventional REST semantics without hand-rolling content negotiation and error handling in every controller.
What You Get
- A
Viewlayer that lets controllers return domain objects while the bundle handles format selection and serialization - Accept-header and custom mime-type based content negotiation configurable per route or globally
- RFC 7807-compliant Problem Details error rendering built on the Symfony Serializer or JMSSerializer
- Structured decoding of JSON/XML request bodies into typed parameters
- Configurable mapping from exception classes to HTTP response status codes
Common Use Cases
- Building versioned JSON REST APIs on top of an existing Symfony application without adopting API Platform
- Standardizing error responses across an API so clients get consistent RFC 7807 problem-details payloads
- Supporting multiple response formats (JSON, XML, custom vendor mime types) from the same controller action
- Migrating legacy Symfony API controllers to a structured view/serialization pipeline incrementally
Under The Hood
Architecture The bundle hooks into Symfony’s kernel via event listeners (EventListener/) that intercept controller results and exceptions, wrapping return values in a View object (View/) that a ViewHandler renders according to negotiated format; Negotiation/ implements Accept-header parsing, Decoder/ handles inbound body parsing, and Serializer//Normalizer/ bridge to the Symfony Serializer or JMSSerializer for the actual (de)serialization work.
Tech Stack Pure PHP bundle targeting Symfony 5.4 through 8.0 (symfony/framework-bundle, symfony/http-kernel, symfony/routing, symfony/config, symfony/dependency-injection as required dependencies), PHP 7.4/8.x, with optional integration against jms/serializer-bundle for teams not using the core Symfony Serializer.
Code Quality A large Tests/ directory mirrors the module layout (Controller, EventListener, View, Serializer, etc.) with PHPUnit, and the CHANGELOG/UPGRADING files document breaking changes release over release, reflecting the discipline expected of a widely-depended-on Symfony bundle used by thousands of projects.
API Design Configuration is centralized through Symfony’s DependencyInjection extension pattern (DependencyInjection/), which is idiomatic for the ecosystem but means new users must learn Symfony bundle configuration conventions (YAML/PHP config trees) before they can use the View API productively — a moderate learning curve for anyone new to Symfony bundles specifically.
Used by 3 apps in this directory
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.