If you use annotations for routes and activate controllers in routing.yml, you can do this:
Api:
resource: "@ApiBundle/Controller"
type: annotation
defaults: { _format: 'json' }
If you want to install it for only one controller, set it to controller level annotations:
class ApiController
{
}
source
share