FOSRestBundle adds Symfony tools to build REST APIs faster, including format-agnostic controllers, content negotiation, and structured API errors.
Overview
FOSRestBundle is a Symfony bundle focused on REST-style HTTP APIs and applications. It layers conventions and helpers on top of Symfony so controllers can stay independent of specific output formats while still returning JSON, XML, or other negotiated representations.
Documented capabilities include a view layer for format-agnostic controllers, Accept-header negotiation with support for custom MIME types, decoding of request bodies and Accept headers in a REST-oriented way, and mapping exception codes to HTTP status responses. Error rendering can align with RFC 7807 through the Symfony Serializer or JMS Serializer.
Installation and configuration are covered in the bundle’s documentation. The bundle is distributed under the MIT license and is maintained as part of the FriendsOfSymfony ecosystem for PHP projects that already use Symfony.
Teams choose it when they want Symfony’s routing and dependency injection model but need shared patterns for media types, serialization, and API error shapes instead of hand-rolling those concerns in each controller.
Key features
- Format-agnostic view layer
- Accept header negotiation
- REST request body decoding
- Exception to HTTP status mapping
- RFC 7807-compatible error output
- Custom MIME type handling
- Symfony Serializer integration
- JMS Serializer integration
Use cases
- JSON APIs on Symfony
- Multi-format REST endpoints
- Standardized API error responses
- Content negotiation by Accept header