uwebpro/curl-printer

There is no license information available for the latest version (v3.0.0) of this package.

Print psr requests as curl command string

v3.0.0 2023-04-19 12:52 UTC

This package is auto-updated.

Last update: 2024-04-19 14:58:15 UTC


README

curl-printer is a library which allows you print php PSR-7 request as curl command line string. It is useful for logging and debugging

Installation

composer require sergey-bel/curl-printer

Usage

use CurlPrinter\CurlPrinter;
use GuzzleHttp\Psr7\Request;

$request = new Request(
    'POST',
    'https://someapi.com/v2/user/create',
     [
       'Accept' => 'application/json',
     ],
     'user_id=12345'
);
$printer = new CurlPrinter();
echo $printer->printRequest($request); 
// curl -X POST https://someapi.com/v2/user/create -d 'user_id=12345' -H 'Accept: application/json'

Guzzle middleware

You can use CurlPrinterMiddleware for comfortable work with Guzzle (see examples)

$logger = // some LoggerInterface

$stack = // Guzzle handler stack
$stack->push(new CurlPrinterMiddleware($logger));
$client = new Client(['handler' => $stack]);
$client->post(...);