title: How to pass token in rest API?
body: <p>I am exploring the world of the REST API for the first time, I have already had to deal with it through the use of Slim, but now I want to be a homemade solution, considering that I don't need any framework for make a simple Rest Api.
  What I have done is create a page like this:</p>
  
  <pre><code>&lt;?php
  $method = $_SERVER['REQUEST_METHOD'];
  $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
  
  switch ($method) 
  {
    case 'PUT':
      echo "PUT";
      break;
    case 'POST':
      echo "POST";
      break;
    case 'GET':
      echo "GET";
      break;
    case 'DELETE':
      echo "DELETE";  
      break;
    default:
      handle_error($request);  
      break;
  }
  </code></pre>
  
  <p>My goal is to implement an access token, I think passing it in the header but I'm not sure (I'm looking for a secure mode). However if I run this from the command line:</p>
  
  <pre><code>curl -X GET http://localhost/v1
  </code></pre>
  
  <p>I get <code>GET</code>, just to give an example of how it should work. And so for all other inquiries. Now the real question is: how can I call the methods in the switch only if I passed a token? For example, at the top of the page will be performed control will be carried out such a check:</p>
  
  <pre><code>if(!isset($_SERVER['AUTH_USER'])) 
  {
      exit('TOKEN not provide');
  }
  </code></pre>
  
  <p>Another question is how to pass the token via curl? Because if I do it through ...
  I can read the header via curl but how would it work?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>As mentioned by @Paradoxis I've tried with:</p>
  
  <pre><code>url http://localhost/v1 -H "Authorization: &lt;token&gt;"
  </code></pre>
  
  <p>but seems that I fail to take the header. I spend my time to understand why the header isn't passed, so in my code I've add this line:</p>
  
  <pre><code>print_r(apache_request_headers());
  </code></pre>
  
  <p>and this is the result:</p>
  
  <pre><code>Array 
  (
     [Host] =&gt; localhost
     [User-Agent] =&gt; curl/7.46.0
     [Accept] =&gt; */*
     [Authorization] =&gt; &lt;token&gt;
  )
  </code></pre>
  
  <p>How you can see in the <code>request_headers</code> I can see correctly in the header, but I can't catch it through the use of <code>$_SERVER['Authorization']</code> or <code>$_SERVER['HTTP_Authorization']</code></p>