0

I used Swagger to generate a Slim framework for a server. Without editing anything, I am testing the basic functions. I have one located at /user/login. Here is the script I have for it:

$app = new Slim\App();
$app->POST('/user/login', function($request, $response, $args) {

    $queryParams = $request->getQueryParams();
    $username = $queryParams['username'];
    $password = $queryParams['password'];

    $response->write("Will not work");
    return $response;
});
$app->GET('/user/{user_id}', function($request, $response, $args) {

    $response->write('Works');
    return $response;
});

However, when I try to POST to the url using Postman (chrome app), it results in a 500 error. If I try any of the GET methods, it works. It only seems to be happening with the POST methods.

I have it running on an Ubuntu machine, with Apache2 installed with PHP. I have updated everything to the latest available versions. ModRewrite is enabled, and the override is set to all. Please help! I am at such as loss at this point.

Brian Logan
  • 812
  • 2
  • 6
  • 20

1 Answers1

0

I found the error.

Notice that I have two urls, one at /user/login and /user/{user_id}, because of the two starting /user urls, it confuses and doesn't know which to use, resulting in a 500 error.

Switching the /user/login to /login corrected the issue.

I feel stupid for not knowing that would happen.

Brian Logan
  • 812
  • 2
  • 6
  • 20
  • That shouldn't be the problem as one is a post() and one is a get(). I tested with your code sample and it works for me. Since Slim 3.2, you should get a message in your error log showing you the actual error. – Rob Allen Mar 05 '16 at 13:06