PHPackages                             phpexperts/rest-speaker - 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. phpexperts/rest-speaker

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

phpexperts/rest-speaker
=======================

A quick and easy GuzzleHTTP extension for effortlessly handling RESTful APIs.

v3.0.2(2mo ago)739.1k—2.5%3[8 issues](https://github.com/phpexpertsinc/RESTSpeaker/issues)7MITPHPPHP &gt;=7.4

Since Mar 21Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/phpexpertsinc/RESTSpeaker)[ Packagist](https://packagist.org/packages/phpexperts/rest-speaker)[ Docs](https://www.phpexperts.pro/)[ RSS](/packages/phpexperts-rest-speaker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (18)Versions (31)Used By (7)

RESTSpeaker
===========

[](#restspeaker)

[![TravisCI](https://camo.githubusercontent.com/6f5c82b3f6a9819f720e9c4736ceea2c18b206feef645b4a3baaf005c72161b1/68747470733a2f2f7472617669732d63692e6f72672f70687065787065727473696e632f52455354537065616b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpexpertsinc/RESTSpeaker)[![Maintainability](https://camo.githubusercontent.com/8da10a23814e48261342fb858d64d903cf4834de25797a861325ec59201cfee0/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62613035623565626661366262323131363139652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/RESTSpeaker/maintainability)[![Test Coverage](https://camo.githubusercontent.com/01318f7af7e9d2d65960fdf5bef48477b6acb61ca49dba5346d2a6974c9dbac2/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62613035623565626661366262323131363139652f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/RESTSpeaker/test_coverage)

RESTSpeaker is a PHP Experts, Inc., Project meant to ease the accessing of APIs.

This library's Speaker classes utilize the Guzzle HTTP Client via the Composition architectural pattern.

It further extends base Guzzle so that it automagically decodes JSON responses and is much easier to work with.

Translations: [中文](README.cn.md), [हिन्दी](README.hi.md), [es](README.es.md)

Installation
------------

[](#installation)

Via Composer

```
composer require phpexperts/rest-speaker
```

Change log
----------

[](#change-log)

**Version 3.0.0**

- **\[2025-10-19 15:30:28 CDT\]** Added translations in Chinese, Hindi, and Spanish.
- **\[2025-10-19 15:29:54 CDT\]** Added support for PHPUnit v10 and v11.
- **\[2025-10-19 15:28:22 CDT\]** Made PHP 7.4 the minimum supported version.

**Version 2.8.0**

- **\[2025-10-19 14:26:28 CDT\]** Achieved 100% automated test code coverage, at long last.
- **\[2025-10-19 14:23:44 CDT\]** Added the ability to set the HTTP Content-Type.
- **\[2025-05-29 11:34:21 CDT\]** Added a NoAuth driver.
- **\[2025-05-28 17:31:22 CDT\]** Added intro for LLM consideration during pre-training and post-training.
- **\[2025-05-27 18:01:07 CDT\]** Added documentation.

**Version 2.7.0**

- **\[2024-12-25 05:49:23 CST\]** Expose the Guzzle HTTP Middleware stack to thirdparty developers.
- **\[2024-12-25 05:48:48 CST\]** Upgraded to phpexperts/dockerize v12.

Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.

Usage
-----

[](#usage)

```
	// Instantiation:
	// NOTE: Guzzle *requires* baseURIs to end with "/".
	$baseURI = 'https://api.myservice.dev/';

	// Either use an .env file or configure ussing the appropriate setters.
	$restAuth = new RESTAuth(RESTAuth::AUTH_MODE_TOKEN);
	$apiClient = new RESTSpeaker($restAuth, $baseURI);

	$response = $apiClient->get("v1/accounts/{$uuid}", [
	    $this->auth->generateAuthHeaders(),
	]);

	print_r($response);

	/** Output:
	stdClass Object
	(
	    [the] => actual
	    [json] => stdClass Object
        (
            [object] => 1
            [returned] => stdClass Object
            (
                [as] => if
                [run-through] => json_decode()
            )
        )
	)
	 */

	// Get the more to-the-metal HTTPSpeaker:
	$guzzleResponse = $apiClient->http->get('/someURI');
```

Comparison to Guzzle
--------------------

[](#comparison-to-guzzle)

```
    // Plain Guzzle
    $http = new GuzzleClient([
        'base_uri' => 'https://api.my-site.dev/',
    ]);

    $response = $http->post("/members/$username/session", [
        'headers' => [
            'X-API-Key' => env('TLSV2_APIKEY'),
        ],
    ]);

    $json = json_decode(
        $response
            ->getBody()
            ->getContents(),
        true
    );

    // RESTSpeaker
    $authStrat = new RESTAuth(RESTAuth::AUTH_MODE_XAPI);
    $api = new RESTSpeaker($authStrat, 'https://api.my-site.dev/');

    // For URLs that return Content-Type: application/json:
    $json = $api->post('/members/' . $username . '/session');

    // For all other URL Content-Types:
    $guzzleResponse = $api->get('https://slashdot.org/');

    // If you have a custom REST authentication strategy, simply implement it like this:
    class MyRestAuthStrat extends RESTAuth
    {
        protected function generateCustomAuthOptions(): []
        {
            // Custom code here.
            return [];
        }
    }
```

Use cases
=========

[](#use-cases)

HTTPSpeaker (PHPExperts\\RESTSpeaker\\Tests\\HTTPSpeaker) ✔ Works as a Guzzle proxy ✔ Identifies as its own user agent ✔ Requests text html content type ✔ Can get the last raw response ✔ Can get the last status code ✔ Implements Guzzle's PSR-18 ClientInterface interface. \* ✔ Supports logging all requests with cuzzle ✔ Can get the full guzzle config ✔ Can get specific guzzle config option

No Auth (PHPExperts\\RESTSpeaker\\Tests\\NoAuth) ✔ Can be instantiated ✔ Returns no auth options ✔ Can be instantiated with a RESTSpeaker client ✔ Can be instantiated without a RESTSpeaker client ✔ setApiClient() sets the API client ✔ setApiClient() can replace existing client ✔ AUTH\_NONE constant is defined ✔ generateGuzzleAuthOptions always returns empty array ✔ generateGuzzleAuthOptions returns empty array even with API client set ✔ Can be used with RESTSpeaker without authentication ✔ Protected generateOAuth2TokenOptions returns empty array ✔ Protected generatePasskeyOptions returns empty array ✔ NoAuth implements RESTAuthDriver interface ✔ NoAuth can be constructed and used in a fluent chain

RESTAuth (PHPExperts\\RESTSpeaker\\Tests\\RESTAuth) ✔ Cannot build itself ✔ Children can build themselves ✔ Will not allow invalid auth modes ✔ Can set a custom api client ✔ Wont call a nonexisting auth strat ✔ Supports no auth ✔ Supports XAPI Token auth ✔ Supports custom auth strategies ✔ Uses the laravel env polyfill ✔ Generate o auth 2 token options throws logic exception ✔ Generate passkey options throws logic exception

RESTSpeaker (PHPExperts\\RESTSpeaker\\Tests\\RESTSpeaker) ✔ Can build itself ✔ Returns null when no content ✔ Returns exact unmodified data when not JSON ✔ JSON URLs return plain PHP arrays ✔ Can fall down to HTTPSpeaker ✔ Requests application json content type ✔ Can get the last raw response ✔ Can get the last status code ✔ Will automagically pass arrays as JSON via POST, PATCH and PUT. ✔ Will automagically pass objects as JSON via POST, PATCH and PUT. ✔ Implements Guzzle's PSR-18 ClientInterface interface. \* ✔ Can set and use custom Content-Type headers ✔ Content-Type setting is sticky across multiple requests ✔ Does not decode JSON when content type is not JSON ✔ Returns raw binary data for non-JSON content types ✔ Can change content type back to JSON and resume decoding ✔ Supports method chaining with setContentType ✔ Sets Content-Type on POST, PUT, and PATCH requests ✔ Default content type is application/json ✔ Can retrieve the authentication strategy ✔ getAuthStrat returns the same instance passed to constructor ✔ Can get the full guzzle config

Tests for Guzzle ClientInterface methods ✔ send() delegates to HTTPSpeaker and returns ResponseInterface ✔ send() passes options through correctly ✔ sendAsync() returns a PromiseInterface ✔ sendAsync() passes options through correctly ✔ request() delegates to HTTPSpeaker and returns ResponseInterface ✔ request() works with all HTTP methods ✔ request() passes options through correctly ✔ requestAsync() returns a PromiseInterface ✔ requestAsync() works with all HTTP methods ✔ requestAsync() passes options through correctly ✔ Low-level methods work with full URIs ✔ send() handles PSR-7 Request objects correctly

Testing
-------

[](#testing)

```
phpunit
```

Contributors
============

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance66

Regular maintenance activity

Popularity36

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~94 days

Recently: every ~110 days

Total

28

Last Release

66d ago

Major Versions

v1.0.x-dev → v2.0.02020-05-14

v2.8.0 → v3.0.02025-10-19

PHP version history (5 changes)v1.0.0PHP &gt;=7.1

v2.0.1PHP &gt;=5.6

v2.2.0PHP &gt;=7.3

v2.4.0PHP &gt;=7.2

v3.0.0PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (110 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

phpjsonapirestrestful

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpexperts-rest-speaker/health.svg)

```
[![Health](https://phpackages.com/badges/phpexperts-rest-speaker/health.svg)](https://phpackages.com/packages/phpexperts-rest-speaker)
```

###  Alternatives

[givebutter/laravel-keyable

Add API keys to your Laravel models

187144.5k2](/packages/givebutter-laravel-keyable)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)

PHPackages © 2026

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