I am using Dingo with Laravel 5.1 to create a simple API.
So on route.php I have:
$api = app('Dingo\Api\Routing\Router'); $api->version('v1', function($api) { $api->get('getvoucher', 'App\Http\Controllers\ BitemsController@index '); $api->get('update/{key}', 'App\Http\Controllers\ BitemsController@update '); $api->post('store', 'App\Http\Controllers\ BitemsController@store '); $api->post('authenticate', 'App\Http\Controllers\ AuthenticateController@authenticate '); $api->post('logout', 'App\Http\Controllers\ AuthenticateController@logout '); $api->get('token', 'App\Http\Controllers\A uthenticateController@getToken '); });
and my BitemsController:
public function index(Request $request) { $bitem = Bitem::where('key',$request->key)->where('id',$request->pin)->first(); return $bitem; } public function store(Request $request) { $bitem = new Bitem($request->all()); $bitem->save; return $bitem; }
Now I use the POSTMAN application to test the API, and when I send GET to localhost: 8888 / api / getvoucher, everything is fine, but when I make a POST request to store some data, I got an error:
"message": "500 Internal Server Error", "status_code": 500, "debug": { "line": 53, "file": "C:\\wamp\\www\\dine\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php", "class": "Illuminate\\Session\\TokenMismatchException", "trace": [
POSTMAN: 
To fix the problem, I am trying to add:
protected $except = [ 'api/*', ];
inside the middleware VerifyCsrfToken.php, but wnt works.
Please tell me how to solve my problem ...
php middleware csrf laravel dingo-api
Aleks Per
source share