I'd like the response for any URL starting with /api
to be in JSON format. Is there a way to configure this for my whole application? I'm using Symfony2 version 2.0.
If you are using annotations for routes and activate controllers in routing.yml
, you could do this:
Api:
resource: "@ApiBundle/Controller"
type: annotation
defaults: { _format: 'json' }
If you want to set it for one controller only, set it on the controller level annotation:
/**
* @Route("/api", defaults={"_format": "json"})
*/
class ApiController
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With