I have developed apis into php laravel, and developing on the local server and running them using
php artisan serve
these apis are working in the website but whenever i try to access them in postman it returns 419 response code with a message Page Expired.
After googling the debugging the requests from websites i found out headers to pass with the request. So i passed
_token
X-CSRF-Token
and also selected Bearer Token in Authorization tab. Even after adding these parameters in headers it did not work out. I tried adding them with body but it did not work there as well.
The code snippets are
Route::post('/register_user', 'MyUserController@storeApi');
MyUserController
public function storeApi(Request $request)
{
$userModel = new User;
$userModel->first_name = $request->input('first_name');
$userModel->last_name = $request->input('last_name');
$userModel->save();
$userId = DB::getPdo()->lastInsertId();
$response['status'] = 'ok';
$response['response'] = $userId ;
return response()->json($response);
}
So my question is, how to make it work in local server using postman.
use api.php
file
and call the route with api prefix like this :
in api.php :
Route::get('/test','Controller@function');
in postman :
GET: localhost:8000/api/test