Rox
Rox

Reputation: 811

Lumen API with OAuth, Guzzle get/post method

I'm building a Lumen API with OAuth2 authentication, i followed this tutorial : http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/ but i'm getting an error : "Fatal error: Maximum execution time of 60 seconds exceeded in C:\Users\user\Desktop\api\lumen\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php on line 99"
Guzzle's post method ( and get method too) doesn't work for me

$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('localhost:8000/api/hello');
return $response;
});

$app->get('api/hello', function() use ($app) {
return "Hello";
});

get me same errors

Upvotes: 4

Views: 3992

Answers (1)

Rox
Rox

Reputation: 811

I solved my problem :

POST and GET requests from my API to my API don't work because I was using

php artisan serve

so requests from localhost:8000/api on localhost:8000/api/hello didn't work but GET requests from localhost:8000/api on http://www.google.com/ did.
Example :

$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('http://www.google.com/');
return $response;
});


I had to deploy my Lumen API directly on localhost in www/ folder ( C:\wamp\www on windows or /var/www/html/ on linux )

$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('localhost/api/hello');
return $response;
});

$app->get('api/hello', function() use ($app) {
return "Hello";
});

And now it works.

For those who don't know how to deploy your Lumen API on localhost (or your server ) :
My Lumen project is located in C:\wamp\www\api Create a .htaccess in project root so its path is C:\wamp\www\api\.htaccess with

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>

Rename C:\wamp\www\api\server.php by C:\wamp\www\api\index.php
In your C:\wamp\www\api\public\index.php change

$app->run();

with

$request = Illuminate\Http\Request::capture();
$app->run($request);

Don't forget to activate mod_rewrite !

Upvotes: 4

Related Questions