title: How to determine where a request is coming from in a REST api
body: <p>I have an RESTful API with controllers that should return a JSON response when is being hit by my android application and a &quot;view&quot; when it's being hit by a web browser. I'm not even sure I'm approaching this the right way. I'm using Laravel and this is what my controller looks like</p>
  <pre><code>class TablesController extends BaseController {
  
      public function index()
      {
          $tables  = Table::all();
  
          return Response::json($tables);
      }
  }
  </code></pre>
  <p>I need something like this</p>
  <pre><code>class TablesController extends BaseController {
  
      public function index()
      {
          $tables  = Table::all();
  
          if(beingCalledFromWebBrowser){
              return View::make('table.index')-&gt;with('tables', $tables);
          }else{ //Android 
              return Response::json($tables);
          }
      }
  </code></pre>
  <p>See how the responses differ from each other?</p>