title: Symfony2 + FOSRestBundle + FrameworkExtraBundle Disable rest and error when using @Template
body: <p>I am trying to setup my application so the same action can return responses for both web and api. This working great but sometimes the action is only required for the website and not the api. I am looking for a way to enable/disable this functionality per action/controller.</p>
  
  <p>I've created two demo actions to test with, but have been unable to make one <strong>not</strong> respond on the api url.</p>
  
  <p><strong>Website is accessible via domain.com</strong></p>
  
  <p><strong>Api is accessible via api.domain.com</strong> - All requests to the api are formatted as json using the format listener in the config</p>
  
  <pre><code>- { path: '^/', host: 'api.domain.dev', priorities: ['json'], fallback_format: ~, prefer_extension: false }
  </code></pre>
  
  <p>The first action(indexAction) works fine returning both HTML and Json depending on which domain you use. The problem is with the second action(testAction) and I want this to only work on the website domain. When visiting api.domain.com/company-test the response is the template HTML with the content-type header set to application/json. </p>
  
  <p><strong>Is there a way to make this return an error(404?) when the JSON version is not available and @Template is being used?</strong></p>
  
  <p>Test Actions</p>
  
  <pre><code>use FOS\RestBundle\Controller\Annotations as Rest;
  use FOS\RestBundle\View\View;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use Nelmio\ApiDocBundle\Annotation\ApiDoc;
  
  /**
   * Get a list of companies
   *
   * @Rest\Get("/company")
   * @Rest\View(
   *     template = "CompanyBundle:Company:index.html.twig",
   *     templateVar = "companies",
   *     statusCode = 200,
   * )
   *
   * @ApiDoc(
   *     description=""
   * )
   */
  public function indexAction() {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $companies = $em-&gt;getRepository('CompanyBundle:Company')-&gt;findAll();
  
      $view = View::create();
  
      $view-&gt;setData($companies);
      $view-&gt;setTemplateData(['extraData' =&gt; 'Hello World!']);
      return $view;
  }
  
  
  /**
   * Get a list of companies
   *
   * @Route("/company-test")
   *
   * @ApiDoc(
   *     description=""
   * )
   *
   * @Template(
   *     template="CompanyBundle:Company:index.html.twig"
   * )
   */
  public function testAction() {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $companies = $em-&gt;getRepository('CompanyBundle:Company')-&gt;findAll();
  
      return [
          'companies' =&gt; $companies,
          'test-test' =&gt; 'Hello World!'
      ];
  }
  </code></pre>