"After" callback function with request, response and request time for http requests with Laravel Http
facade.
You can install the package via composer:
composer require trin4ik/laravel-http-after
This package makes use of Laravels package auto-discovery mechanism so there is no need to do any futher steps - skip directly to the usage section below. If for some reason you wish to opt-out of package auto discovery, check the Laravel Docs for more details.
NOTE: Lumen is not officially supported by this package. However, we are currently not aware of any incompatibilities.
If you use Lumen register the service provider in bootstrap/app.php
like so:
<?php
// bootstrap/app.php
$app->register(Trin4ik\LaravelHttpAfter\LaravelHttpAfterServiceProvider::class);
// If you want to use the Facades provided by the package
$app->withFacades();
use GuzzleHttp\Psr7\Message;
use Illuminate\Support\Facades\Http;
Http::after(function ($request, $response, $time) {
echo "time: " . $time . PHP_EOL;
echo "request:" . PHP_EOL . Message::toString($request) . PHP_EOL;
echo "response:" . PHP_EOL . Message::toString($response) . PHP_EOL;
})->get('https://example.com');
time: 0.49774980545044
request:
GET / HTTP/1.1
User-Agent: GuzzleHttp/7
Host: example.com
response:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 443743
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Tue, 26 Apr 2022 15:16:17 GMT
Etag: "3147526947+gzip"
Expires: Tue, 03 May 2022 15:16:17 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (bsa/EB19)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
<!doctype html>...
based on laravel-http-client-logger by Anders Bilfeldt
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.