title: Laravel 5.4 Api Route 401
body: <p>I built a new laravel 5.4 project.</p>
  
  <p>I tried to do the steps below in my api route, but somehow they do not work.</p>
  
  <p>In my app.js file I have this ajax call:</p>
  
  <pre><code>$.ajaxSetup({
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
      }
  });
  $.ajax({
      url: 'api/postStream',
      type: 'post',
      data: { imgData: imgData },
      success:function(data) {
          console.log('success');
      }
  });
  </code></pre>
  
  <p>My Api Route looks like this:</p>
  
  <pre><code>Route::group(['middleware' =&gt; 'auth:api'], function()
  {
      Route::post('postStream', ['as' =&gt; 'image', 'uses' =&gt; 'ApiController@postStream']);
  });
  </code></pre>
  
  <p>And my controller:</p>
  
  <pre><code>public function postStream(Request $request)
  {
      $imgData = $request-&gt;imgData;
      ...
  }
  </code></pre>
  
  <p>But I get this error in my chrome dev console:</p>
  
  <pre><code>POST http://localhost/app/public/api/postStream 401 (Unauthorized)
  </code></pre>
  
  <p>And in the network tools this:</p>
  
  <pre><code>{error: "Unauthenticated."}
  error
  :
  "Unauthenticated."
  </code></pre>
  
  <p>I guess I am somewhat not authentificated, but I do not know how to make that happen this way.</p>