Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

leonvr's avatar

API Call not returning a response

This works fine: http://127.0.0.1:8000/api/all

//api.php:

Route::get('all', function () {
    return 'everybody may access this api route';
});

But when I call the same route from within another route, I never get a response, and it keeps spinning...

What am I doing wrong?

api.php:

Route::get('/test', 'AuthController@test');

//AuthController.php:

...
use GuzzleHttp\Client;

class AuthController extends Controller
{
    public function test(Request $request)
    {
        $client = new Client([
            'timeout'  => 8.0,
        ]);

        //return 'gets here ok1';
        $response = $client->get('http://127.0.0.1:8000/api/all');
        //return 'does NOT get here';
        //500 internal error, the timeout I set at above line, otherwise it keeps spinning
        return $response->getBody();
    }
}

So http://127.0.0.1:8000/api/test never gets back...

0 likes
5 replies
Snapey's avatar
Snapey
Best Answer
Level 122

As a guess, you are using PHP webserver (php artisan serve) ?

It only handles one request at a time, so you cannot start another request from inside a request.

1 like
leonvr's avatar

I am using php artisan serve

My code is a simplified version of the api/login route in this project: https://github.com/drehimself/todo-laravel

It is the same pattern: http://todo-laravel.test/api/login leading to an internal call http://todo-laravel.test/oauth/token video: https://youtu.be/HGh0cKEVXPI?list=PLEhEHUEU3x5q-xB1On4CsLPts0-rZ9oos&t=876

I do not know which server he is running.

But you are saying this is not able to work with php artisan serve? I am new to Laravel, but this is not an uncommon pattern for an api?

Is there a local webserver (simple to use), which you would recommand, and is able to run this? And do you think this will work in a standard production environment?

A lot of questions, but I appreciate your help.

leonvr's avatar

You are right. I managed to run the code using xampp/apache. Thanks

jerov's avatar

@leonvr You did not explain how you solved it. I solved mine by running two servers on different ports. So my API runs on maybe 8000 and web runs on 8001

I used this command: php -S localhost:8001 -t public/

Snapey's avatar

Sorry, i have been away. glad you got it sorted.

Please or to participate in this conversation.