FOSRestBundle

Symfony bundle that turns controllers into format-agnostic REST endpoints with content negotiation and view layer

Framework
Composer
v3.9.0
2,796stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
56/100Fair
Development Activity4
Maintenance32
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture74
Code Quality72
Innovation60
Learning Curve55

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 View layer 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search