In fact there is no way to detect if it is real ajax (and this is what helps us), what we do is a send a header which uses the prefix x-, generally in HTTP the use of this prefix means experimental.
A use case of this is jQuery, for example I create a simple GET request with XmlHttpRequest with nothing I won’t have to detect, so jQuery sends this header:
X-Requested-With: XMLHttpRequest
Doesn’t mean it’s Ajax, it actually means it’s XMLHttpRequest (as explained here Ajax is not a programming language. So what is?)
In case we detect if the shipment is XMLHttpRequest, in the Guzzle\Http you can define in the instance of Guzzle\Http, to "inherit" the settings in other requests. Thus, you simplify the configuration:
$client = new Guzzle\Http(['headers' => ['X-Request-With' => 'XMLHttpRequest']]);
$client->put(/** **/);
$client->post(/** **/);
$client->get(/** **/);
Or using the GuzzleHttp\Client thus:
$client = new GuzzleHttp\Client(...);
$client->request('GET', '/caminho/foo/bar/baz', [
'headers' => ['X-Requested-With' => 'XMLHttpRequest']
]);
Just an additional one, frameworks like Laravel and cakephp use these methods to detect if it has the header X-Requested-With' => 'XMLHttpRequest:
The person who gave the negative could offer information on what could be improved in the question.
– Wallace Maxters