title: Add JSON routes for all routes to handle backend requests
body: <p>I'm using Laravel 5.1 and am building a service that can be seen as JSON or HTML. This approach is already done by sites like reddit.<br>
  <strong>Example</strong><br>
  Normal view: <a href="http://www.reddit.com/r/soccer" rel="nofollow">http://www.reddit.com/r/soccer</a><br>
  JSON view: <a href="http://www.reddit.com/r/soccer.json" rel="nofollow">http://www.reddit.com/r/soccer.json</a></p>
  
  <p>As you can see, they simply add <code>.json</code> to an URL and the user is able to see the exact same content either as HTML or as JSON.</p>
  
  <p>I now wanted to reproduce the same in Laravel, however I'm having multiple issues.</p>
  
  <p><strong>Approach 1 - Optional parameter</strong> </p>
  
  <p>The first thing I tried was adding optional parameter to all my routes</p>
  
  <pre><code>Route::get('/{type?}', 'HomeController@index');
  Route::get('pages/{type?}', 'PageController@index');
  </code></pre>
  
  <p>However, the problem I was facing here, is that all routes were caught by the HomeController, meaning <code>/pages/?type=json</code> as well as <code>/pages?type=json</code> were redirected to the HomeController. </p>
  
  <p><strong>Approach 2 - Route Grouping with Namespaces</strong>  </p>
  
  <p>Next I tried to add route groupings with namespaces, to seperate backend and frontend</p>
  
  <pre><code>Route::get('pages', 'PageController@index');
  Route::group(['prefix' =&gt; 'json', 'namespace' =&gt; 'Backend'], function(){
      Route::get('pages', 'PageController@index');
  });
  </code></pre>
  
  <p>However, this doesn't work either. It does work, when using <code>api</code> as prefix, but what I want, is that I can add <code>.json</code> to every URL and get the results as json. How can I achieve that in Laravel?</p>