trin4ik/laravel-http-after

callback after for laravel http facade

v0.1.1 2023-10-26 15:09 UTC

This package is auto-updated.

Last update: 2024-10-26 17:08:28 UTC


README

Latest Version on Packagist Total Downloads

"After" callback function with request, response and request time for http requests with Laravel Http facade.

Installation

You can install the package via composer:

composer require trin4ik/laravel-http-after

Laravel

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.

Lumen

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();

Usage

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>...

Credits

based on laravel-http-client-logger by Anders Bilfeldt

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.