PHPackages                             cmdrsharp/guzzle-api - 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. cmdrsharp/guzzle-api

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

cmdrsharp/guzzle-api
====================

A cleaner approach to using Guzzle in Laravel

2.2.0.2(5y ago)0168↓100%1MITPHPPHP &gt;=7.4

Since Mar 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/CmdrSharp/guzzle-api)[ Packagist](https://packagist.org/packages/cmdrsharp/guzzle-api)[ RSS](/packages/cmdrsharp-guzzle-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (13)Used By (1)

About
=====

[](#about)

[![Latest Stable Version](https://camo.githubusercontent.com/b7cce9c47f8b8e3f8ae04f0f6de865eca2a5c7e72ec005edf742e7ab9635ccbc/68747470733a2f2f706f7365722e707567782e6f72672f636d647273686172702f67757a7a6c652d6170692f762f737461626c65)](https://packagist.org/packages/cmdrsharp/guzzle-api)[![Build Status](https://camo.githubusercontent.com/ea6eda33849f90cebd6de5484ccf4f875bc1e0d4133c5dff7b82446fea2e4f28/68747470733a2f2f7472617669732d63692e6f72672f436d647253686172702f67757a7a6c652d6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CmdrSharp/guzzle-api)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ab6897d53d636f62e3942546566dd0b61e7a456f38a799a44a7a8a3ae93a8b3c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436d647253686172702f67757a7a6c652d6170692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/CmdrSharp/guzzle-api/?branch=master)[![StyleCI](https://camo.githubusercontent.com/91812102ef2b225425df06a2655f61f867b84542ff0ca59031bf14edee9a6c52/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132363632353033302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/126625030)[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE)

This is an API for GuzzleHTTP. It aims to make using Guzzle a bit more clean and extends reusability.

Requirements
============

[](#requirements)

- PHP 7.4 or newer
- Laravel [8.x](https://laravel.com/docs/8.x) or newer

Note that the above requirements will always reflect the latest release. Older releases may support older PHP and Laravel versions.

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

[](#installation)

Via composer

```
$ composer require cmdrsharp/guzzle-api
```

Usage
=====

[](#usage)

Inject the contract into the class where you need the client:

```
/**
 * @var RequestInterface
 */
protected $client;

/**
 * @param Client $client
 */
public function __construct(Client $client)
{
    $this->client = $client;
}
```

You can then use the client by first calling make, to set the base URI - and then populating the request. The client returns a normal PSR ResponseInterface. This means you interact with the response as you would with any Guzzle response.

```
$this->client = $this->client->make('https://httpbin.org/');

$this->client->to('get')->withBody([
	'foo' => 'bar'
])->withHeaders([
	'baz' => 'qux'
])->withOptions([
	'allow_redirects' => false
])->asJson()->get();

echo $response->getBody();
echo $response->getStatusCode();
```

Alternatively, you can include both the body, headers and options in a single call.

```
$response = $this->client->to('get')->with([
    'foo' => 'bar'
], [
    'baz' => 'qux'
], [
    'allow_redirects' => false
])->asFormParams()->get();

echo $response->getBody();
echo $response->getStatusCode();
```

The `asJson()` method will send the data using `json` key in the Guzzle request. (You can use `asFormParams()` to send the request as form params).

Available methods / Example Usage
=================================

[](#available-methods--example-usage)

```
// GET
$response = $this->client->to('brotli')->get();

// POST
$response = $this->client->to('post')->withBody([
	'foo' => 'bar'
])->asJson()->post();

// PUT
$response = $this->client->to('put')->withBody([
	'foo' => 'bar'
])->asJson()->put();

// PATCH
$response = $this->client->to('patch')->withBody([
	'foo' => 'bar'
])->asJson()->patch();

// DELETE
$response = $this->client->to('delete?id=1')->delete();

// CUSTOM HEADER
$response = $this->client->to('get')->withHeaders([
	'Authorization' => 'Bearer fooBar'
])->asJson()->get();

// CUSTOM OPTIONS
$response = $this->client->to('redirect/5')->withOptions([
	'allow_redirects' => [
		'max' => 5,
		'protocols' => [
			'http',
			'https'
		]
	]
])->get();
```

Debugging
=========

[](#debugging)

Using `debug(bool|resource)` before sending a request turns on Guzzle's debugger, more information about that [here](http://docs.guzzlephp.org/en/stable/request-options.html#debug).

The debugger is turned off after every request, if you need to debug multiple requests sent sequentially you will need to turn on debugging for all of them.

**Example**

```
$logFile = './guzzle_client_debug_test.log';
$logFileResource = fopen($logFile, 'w+');

$this->client->debug($logFileResource)->to('post')->withBody([
	'foo' => 'random data'
])->asJson()->post();

fclose($logFileResource);
```

This writes Guzzle's debug information to `guzzle_client_debug_test.log`.

Versioning
==========

[](#versioning)

This package follows [Explicit Versioning](https://github.com/exadra37-versioning/explicit-versioning).

Authors
=======

[](#authors)

[Dylan DPC](https://github.com/Dylan-DPC)[CmdrSharp](https://github.com/CmdrSharp)

Credits
=======

[](#credits)

Inspired by [Dylan DPC](https://github.com/Dylan-DPC) - the current 1.0.0.0-release is currently also pulled as 0.4.0 in his repo! It's merely re-committed here so that I can easily adapt it as needed in the future.

License
=======

[](#license)

[The MIT License (MIT)](LICENSE)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

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 ~88 days

Recently: every ~45 days

Total

12

Last Release

1999d ago

Major Versions

1.2.0.0 → 2.0.0.02020-03-18

PHP version history (3 changes)1.0.0.0PHP &gt;=7.1

1.2.0.0PHP &gt;=7.2

2.2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3df8f99d6d2e30affeb17bb7d3dab0a5c4142cbcd1ef0e7654097c28f2996249?d=identicon)[CmdrSharp](/maintainers/CmdrSharp)

---

Top Contributors

[![CmdrSharp](https://avatars.githubusercontent.com/u/5938745?v=4)](https://github.com/CmdrSharp "CmdrSharp (46 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cmdrsharp-guzzle-api/health.svg)

```
[![Health](https://phpackages.com/badges/cmdrsharp-guzzle-api/health.svg)](https://phpackages.com/packages/cmdrsharp-guzzle-api)
```

###  Alternatives

[illuminate/http

The Illuminate Http package.

11936.0M5.0k](/packages/illuminate-http)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)

PHPackages © 2026

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