PeregrineStudios's avatar

Lumen POST Routes not Working

Consider the following:

$router->group([
    'prefix' => 'api/v1/group',
    'middleware' => 'auth'
], function () use ($router) {

    $router->get('/', [
        'as'    => 'group.list',
        'uses'  => 'Api\V1\GroupController@list'
    ]);

    $router->post('/', [
        'as'    => 'group.create',
        'uses'  =>'Api\V1\GroupController@create'
    ]);

    $router->get('/{groupUUID}', [
        'as'    => 'group.retrieve',
        'uses'  =>'Api\V1\GroupController@retrieve'
    ]);
    
    $router->put('/{groupUUID}', [
        'as'    => 'group.update',
        'uses'  => 'Api\V1\GroupController@update'
    ]);

    
});

As you can see, a pretty typical route setup. However, I'm seeing some incredibly odd behaviour - in short, the POST route seems to be being interpreted by the app as a GET route. When I make a POST request to api/v1/group (via Postman) I don't see the result of Api\V1\GroupController@create, but the result of Api\V1\GroupController@list.

I wondered if perhaps this was something to do with both routes having the same endpoint (shouldn't matter, but maybe it's different in Lumen? I usually work in full-on Laravel). So I commented out the get route. That made me just see a 404.

I then wondered if perhaps this entire route group was somehow broken. So I made two catchall endpoints:

$router->get('/{any:.*}', function () use ($router) {
    return 'I am a get route';
});

$router->post('/{any:.*}', function () use ($router) {
    return 'I am a post route';
});

And placed them at the top of the routes file, and commented out all other routes. Regardless of the route I hit or the method used, I always saw the same thing: I am a get route.

What's going on? What could cause my app to understand all POST requests as GET requests?

PS: It's also worth noting that these routes were working, until recently, without any real associated changes. Could something have been updated in a Lumen package that caused this?

PPS: I also tried using Insomnia instead of Postman, just in case it was a problem with Postman. Same result.

0 likes
3 replies
bobbybouwmann's avatar

Maybe you routes are cached? Could be something like this

It seems to work fine for me in one of my lumen applications. Do you have any other special config stuff for your application?

PeregrineStudios's avatar

Not really. The server's being administered through serverpilot - along with every other server I have, which continues to operate fine.

How would I hard-clear all caches on a Lumen app? Since a lot of helper artisan commands don't exist.

shez1983's avatar

how about if you commented out the /GET route code to see what it does then? seems weird..

Please or to participate in this conversation.