PHPackages                             ahmard/guzwrap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. ahmard/guzwrap

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ahmard/guzwrap
==============

A wrapper around popular php http client, "GuzzleHttp"

2.4.4(3y ago)103523MITPHPPHP ^8.1CI failing

Since May 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Ahmard/guzwrap)[ Packagist](https://packagist.org/packages/ahmard/guzwrap)[ RSS](/packages/ahmard-guzwrap/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (3)Versions (43)Used By (3)

Guzwrap
=======

[](#guzwrap)

Guzwrap is an object-oriented wrapper around [GuzzleHttp](http://guzzlephp.org/).
This project is founded to make sending request with Guzzle easier and enjoyable.

Supported PHP Versions
----------------------

[](#supported-php-versions)

Guzwrap require **PHP &gt;= 7.4 or &gt;= 8.0**.

Installation
============

[](#installation)

Make sure you have [Composer](http://getcomposer.org) installed.

```
composer require ahmard/guzwrap
```

Usage
=====

[](#usage)

```
use Guzwrap\Request;

//simple request
$result = Request::get('http://localhost:8002')->exec();

//with authentication
Request::get('http://localhost:8002')
    ->auth('username', 'password')
    ->exec();
```

- get Guzwrap Instance

```
use Guzwrap\Request;

$instance = Request::create();
//Do something...
```

- Request with cookies

```
use Guzwrap\Request;

Request::create()->get('http://localhost:8002')
    ->withCookie()
    //or use cookie file
    ->withCookieFile('path/to/file')
    //use cookie session
    ->withCookieSession('session_name')
    //use array too
    ->withCookieArray([
        'first_name' => 'Jane',
        'other_names' => 'Doe'
    ], 'localhost')
    //Use single cookie across requests
    ->withSharedCookie();
```

- Handle redirects

```
use Guzwrap\Request;
use Guzwrap\Wrapper\Redirect;

Request::get('http://localhost:8002')
    ->redirects(function(Redirect $redirect){
        $redirect->max(5);
        $redirect->strict();
        $redirect->referer('http://goo.gl');
        $redirect->protocols('http');
        $redirect->trackRedirects();
        $redirect->onRedirect(function(){
            echo "Redirection detected!";
        });
    })->exec();
```

- Headers

```
use Guzwrap\Request;
use Guzwrap\Wrapper\Header;

Request::get('http://localhost:8002')
    ->header(function(Header $header){
        $header->add('hello', 'world');
        $header->add('planet', 'earth');
    })
    ->exec();
```

- Query

```
use Guzwrap\Request;

Request::get('https://google.com')
    ->query('q', 'Who is jane doe')
    ->exec();
```

- Post form data

```
use Guzwrap\Request;
use Guzwrap\Wrapper\Form;

Request::uri('http://localhost:8002')
    ->post(function(Form $form){
        $form->field('first_name', 'Jane');
        $form->field('last_name', 'Doe');
    })
    ->exec();

//Post with multipart data
Request::uri('http://localhost:8002')
  ->post(function(Form $form){
      $form->method('post');
      $form->field('full_name', 'Jane Doe');
      $form->file('avatar', 'C:\jane_doe.jpg');
  })->exec();
```

You can use [RequestInterface::form()](src/RequestInterface.php) method

**Note:** If you did not set form method to post, all your input fields will be treated as url queries.

```
use Guzwrap\Request;
use Guzwrap\Wrapper\Form;
use Guzwrap\Wrapper\File;

Request::form(function (Form $form){
    $form->method('get'); //You can use any http method here
    $form->action('localhost:8002');
    $form->field('name', 'Guzwrap');
})->exec();

//Send file with custom information
Request::form(function(Form $form){
    $form->method('post');
    $form->action('http://localhost:8002');
    $form->field('full_name', 'Jane Doe');
    $form->file(function(File $file){
        $file->field('avatar');
        $file->path('C:\jane_doe.jpg');
        $file->name('John_doe.gif');
    });
})->exec();
```

### More *Request* usage

[](#more-request-usage)

- Use request data

```
use Guzwrap\Request;
use Guzwrap\UserAgent;

//Basic usage
$request = Request::query('artist', 'Taylor Swift')
    ->useData([
        'headers' => [
            'pass' => 'my-random-pass',
            'user-agent' => 'My Custom Useragent',
        ],
        'query' => [
            'action' => 'create'
        ]
    ])->exec();

//User other request's data
$request1 = Request::userAgent(UserAgent::FIREFOX)
    ->query([
        'username' => 'Ahmard',
        'realm' => 'admin'
    ]);

$realRequest = Request::useData($request1->getData());
```

- Use request object

```
use Guzwrap\Request;
use Guzwrap\UserAgent;

$request1 = Request::query('username', 'Ahmard');

$request2 = Request::query('language', 'PHP')
    ->userAgent(UserAgent::CHROME)
    ->allowRedirects(false);

$realRequest = Request::useRequest($request1, $request2); //Has request 1 and request 2 data
```

### Asynchronous Operations

[](#asynchronous-operations)

```
use Guzwrap\Request;
use Psr\Http\Message\ResponseInterface;

$promise = Request::get('localhost:8002')
    ->query('wraps', 'guzzlehttp')
    ->query('name', 'guzwrap')
    ->execAsync();

$promise->then(function (ResponseInterface $response){
    var_dump($response->getBody()->getContents());
});

$promise->wait();
```

- **Running multiple requests at once**

    - Create [PHP Built-in Server](https://www.php.net/manual/en/features.commandline.webserver.php)

    ```
    php -S localhost:8002 index.php
    ```

    - Create an **index.php** file and put below code into it

    ```
    \sleep($_GET['sleep']);
    echo $_GET['sleep'];
    ```

    - Crate **test.php** and put below code into it

    ```
    use Guzwrap\Request;
    use Psr\Http\Message\ResponseInterface;

    $promise = Request::get('localhost:8002')
        ->query('wraps', 'guzzlehttp')
        ->query('sleep', 2)
        ->execAsync();

    $promise->then(function (ResponseInterface $response){
        var_dump($response->getBody()->getContents());
    });

    $promise2 = Request::get('localhost:8002')
        ->query('name', 'guzwrap')
        ->query('sleep', 1)
        ->execAsync();

    $promise2->then(function (ResponseInterface $response){
        var_dump($response->getBody()->getContents());
    });

    $promise->wait();
    $promise2->wait();
    ```

    - Now run the **test.php** file

    ```
    php test.php
    ```
- **Using [Concurrent](src/Wrapper/Client/Concurrent.php) class to manage [Guzzle Request Concurrency](https://docs.guzzlephp.org/en/stable/quickstart.html#concurrent-requests)**

    ```
    use Guzwrap\Request;

    $promise1 = Request::get('localhost:8002')->execAsync();
    $promise2 = Request::get('localhost:8002')->execAsync();

    $responses = Request::concurrent($promise1, $promise2)->unwrap();

    echo $responses[0]->getStatusCode() . PHP_EOL;
    echo $responses[1]->getReasonPhrase() . PHP_EOL;
    ```

- **Using request pool**```
    use Guzwrap\Request;
    use Guzwrap\Wrapper\Pool;
    use GuzzleHttp\Exception\RequestException;
    use GuzzleHttp\Psr7\Response;
    use Psr\Http\Message\ResponseInterface;

    require 'vendor/autoload.php';

    $pool = Request::pool(function (Pool $pool) {
        $pool->concurrency(5);
        $pool->fulfilled(function (Response $response, $index) {
            // this is delivered each successful response
        });
        $pool->rejected(function (RequestException $reason, $index) {
            // this is delivered each failed request
        });

        $pool->requests(function ($total) {
            $uri = 'http://127.0.0.1:8002';
            for ($i = 0; $i < $total; $i++) {
                yield new \GuzzleHttp\Psr7\Request('GET', $uri);
            }
        });
    });

    $promise = $pool->promise();

    $promise->then(function (ResponseInterface $response){
        echo "{$response->getStatusCode()} @ {$response->getReasonPhrase()}\n";
    });

    $promise->wait();
    ```

### UserAgent

[](#useragent)

We provide custom user agents to help send request easily.

```
use Guzwrap\Request;
use Guzwrap\UserAgent;

Request::userAgent(UserAgent::CHROME);

//Choose specific useragent index from array
Request::userAgent(UserAgent::CHROME, '1');

//Choose sub-useragent
Request::userAgent(UserAgent::CHROME, '9.1');
```

- List user agents

```
use Guzwrap\UserAgent;

$userAgents = UserAgent::init()->getAvailable();
```

- Get random user agent

```
use Guzwrap\UserAgent;

$randomUA = UserAgent::init()->getRandom();
```

- Add user agents to the collection.
    Please take a look at user agent [definition sample](/src/data/ua/chrome.json)

```
use Guzwrap\UserAgent;

UserAgent::init()->addFile('/path/to/user-agents.json');
```

- Use raw user agent
    Note that you can only pass Guzwrap\\UserAgent class to the request object, nothing more.
    This may open door to other possibilities in the future.

```
use Guzwrap\UserAgent;
use Guzwrap\Request;

$request = Request::userAgent(UserAgent::raw('Browser 1.0 (Windows NT 10.0; Win64; x64)'));
```

### Stack

[](#stack)

Manipulating Guzzle [StackHandler](https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlerstack)

```
use Guzwrap\Request;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;

Request::stack(function (HandlerStack $stack){
    $stack->setHandler(new CurlHandler());
    //Do something here
});
```

### Middleware

[](#middleware)

Adding [middleware](https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware) to GuzzleHttp requests

```
use Guzwrap\Request;
use Psr\Http\Message\RequestInterface;

/**
 * An example of middleware that add header to requests
 * @link https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html
 */
Request::middleware(function(){
    return function (callable $handler){
        return function (
            RequestInterface $request,
            array $options
        ) use ($handler){
            $request = $request->withHeader('X-Guzwrap-Version', 'V2');
            return $handler($request, $options);
        };
    };
});
```

### Extending Guzwrap

[](#extending-guzwrap)

```
use Guzwrap\Wrapper\Guzzle;
use Psr\Http\Message\ResponseInterface;

require 'vendor/autoload.php';

class Client extends Guzzle
{
    public static function create(): Client
    {
        return new Client();
    }

    public function boom(): ResponseInterface
    {
        echo "Executing request...\n";
        return parent::exec();
    }
}

$client = Client::create()
    ->get('localhost:8002')
    ->withCookie()
    ->boom();
```

Testing
-------

[](#testing)

Rust PHP built-in server before running the test

```
php -S localhost:8002 -t tests/raw/

```

Run the test

```
composer test

```

**Enjoy 😎**

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Recently: every ~152 days

Total

42

Last Release

1237d ago

Major Versions

1.2.16 → 2.0.02021-01-24

PHP version history (5 changes)1.1.0PHP ^7.4

1.2.4PHP ^7.4|8.0

1.2.5PHP ^7.4 || ^8.0

2.4.3PHP &gt;=7.4

2.4.4PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b69fe34bd6492697a19cd8f33bde7a381cab0b7f8c0a01dcc7505f482458887?d=identicon)[Ahmard](/maintainers/Ahmard)

---

Top Contributors

[![Ahmard](https://avatars.githubusercontent.com/u/44737217?v=4)](https://github.com/Ahmard "Ahmard (14 commits)")

---

Tags

guzwrapguzzleguzzlehttphttp-clienthttp-requestsphpuser-agentwrapperhttpclientcurlGuzzleguzzlehttp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ahmard-guzwrap/health.svg)

```
[![Health](https://phpackages.com/badges/ahmard-guzwrap/health.svg)](https://phpackages.com/packages/ahmard-guzwrap)
```

###  Alternatives

[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)[opgg/riotquest

RiotQuest, PHP RiotAPI client library that focused on multi request from OP.GG

172.6k](/packages/opgg-riotquest)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
