trin4ik/laravel-http-after

callback after for laravel http facade
2,792 1
Install
composer require trin4ik/laravel-http-after
Latest Version:v0.1.1
PHP:>7.4
License:MIT
Last Updated:Oct 26, 2023
Links: GitHub  ·  Packagist
Maintainer: trin4ik

Callback "After" for Laravel HTTP Client

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.

Related Packages

eleme/laravel-guzzle

laravel guzzle service provider

6,607 6
denpa/laravel-bitcoinrpc

Bitcoin JSON-RPC Service Provider for Laravel

55,152 90
pingpong/facebook

Facebook OAuth v4 for Laravel Framework

29,680 9
darkin1/intercom

Wrapper on the Intercom class provided by Intercom - with support for Laravel 5....

87,945 15
kozz/laravel-guzzle-provider

Guzzle 5/6 Service Provider for Laravel

1,108,315 62