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

TuffRivers's avatar

Do External API Responses run through router ?

Hi All,

I have a general question that involves not just laravel but any framework that uses a router.

Say i have a basic application where a user requests a page with a get request in web.php and is returned a page with a form.

The user fills out the form inputs and clicks submit. The submit routes to a post controller that initiates an HttpRequest post to the 3rd party API which returns some response.

My question:

When the data is returned in the response, does the response still go through the web.php file to get back to the controller? or is it automatically returned to the HttpRequest that initiated the request?

0 likes
4 replies
Cronix's avatar

The submit routes to a post controller that initiates an HttpRequest post to the 3rd party API which returns some response.

If you're using curl or guzzle to make that request to the 3rd party API from within the controller, then no, the response doesn't go through a route. It's returned directly to whatever initiated the request (guzzle/curl/etc).

For instance:

$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
    'auth' => ['user', 'pass']
]);

$result = $res->getBody(); // response is available directly from the guzzle client that initiated the request
TuffRivers's avatar

@Cronix thanks. How does this bypass the htaccess that has all routes directed to index.php if it uses the same port as the web server ?

Cronix's avatar
Cronix
Best Answer
Level 67

Routes only affect http calls to YOUR server/app, not ones you are hitting externally. The only time it wouldn't is if this API is using some sort of callback, but you would know that because you'd need to specify the callback url on your server for it to respond to.

In the example I posted, the guzzle client is making a request to an external server and receiving the result directly. It doesn't even leave the method you're currently in. It has nothing to do with your routes. Think of guzzle as sort of a mini browser. It makes the request, and receives the response directly.

1 like

Please or to participate in this conversation.