rest - Using http request headers with Symfony routing to return different content (html / json) -


i'm working on rest api using fosrestbundle , i'd able use same url returning html , json depending on request accept header; i.e. if call url directly browser (accept : text/html etc) html returned twig file, if making ajax request (accept : application/json etc), json returned using fosrestbundle.

currently can work throwing small if statement @ top of each function check request accept header, if it's asking html returns twig file, if it's asking json hits service.

you should rather send "accept" header requests. read content negotiation (“accept” http header) based routing in symfony2.0 , format listener.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -