2
votes

I have an error when calling for POST requests through API.

If I calling put method through web.php than everything works fine, however when I request PUT(POST) method via api.php - I have 405 error:

"405 Method Not Allowed"

Moreover if I put command php artisan routes:list in a console I could see solely routes which are placed in web.php file. If I, for example, clean web.php I see an empty routes:list despite the fact that api.php file is full.

Get requests from api.php are processing well.

api.php route file:

<?php

use Dingo\Api\Routing\Router;

$router = app(Router::class);

$router->version('v1', function(Router $router){

  $router->group(['namespace'=>'App\Http\Controllers'], function(Router $router){

      $router->post('test', 'PostController@store');

  });    

});
1
If you are sending requests through HTML, you need use method spoofing. If you do not see routes that are defined in api.php in the console (art route:lis) you need to check RouteServiceProvider. Good Luck.Kyslik
@Kyslik Thank you for your support. Could I manually check PUT/POST request through Postman?vppy
Yea requests sent via Postman should work as expected (without the spoofing).Kyslik
If you are sending POST, you need to define a route as Route::post(...) if you are sending (or want to send) PUT you need to define a route as Route::put(...). Obviously something is wrong here, with your api.php; you should paste it here. You can not expect me nor anyone else to guess the contents of the file where the problem is...Kyslik
Excellent, where in the original body is dingo/api mentioned? Wow, I am amazed. Next time include all details from the beginning. Anyway, please do consult dingo wiki, from step 1 to 3. I can tell you now, if you can not figure this out yourself, you do not need dingo/api at all. Just stick to pure Laravel or take a look at spatie's packages instead, that may guide you. I am frank in order to help you in the long run. Good luck! :)Kyslik

1 Answers

0
votes

Such issue could happens if you request your route in Postman through a GET request. Please check it careful if it is not your issue.