PHPackages                             rebelcode/wp-http - 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. rebelcode/wp-http

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

rebelcode/wp-http
=================

A PSR-18 compliant HTTP client adapter for WordPress

0.3(4y ago)8854↓100%1[1 issues](https://github.com/RebelCode/wp-http/issues)MITPHPPHP &gt;=7.1

Since Jun 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/RebelCode/wp-http)[ Packagist](https://packagist.org/packages/rebelcode/wp-http)[ RSS](/packages/rebelcode-wp-http/feed)WikiDiscussions develop Synced today

READMEChangelog (3)Dependencies (9)Versions (5)Used By (0)

RebelCode - WP HTTP Client
==========================

[](#rebelcode---wp-http-client)

[![GitHub Workflow Status](https://camo.githubusercontent.com/23e9d7db807737ce796c2ad629f37e403b3531d3d1c28c6ffbf7a495ba7825bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f726562656c636f64652f77702d687474702f436f6e74696e756f7573253230496e746567726174696f6e)](https://github.com/RebelCode/wp-http/actions/workflows/continuous-integration.yml)[![Packagist PHP Version Support](https://camo.githubusercontent.com/c7bc68e46bea6dc5c1d05ab51e5a7e8421831f30d415d127577f5066d97890e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726562656c636f64652f77702d68747470)](https://packagist.org/packages/rebelcode/wp-http)[![Packagist Version](https://camo.githubusercontent.com/379be66c77a450d7e2a9ad4fa7350e87a147e646a9c7ca7927026a65f98d023c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726562656c636f64652f77702d68747470)](https://packagist.org/packages/rebelcode/wp-http)[![Packagist License](https://camo.githubusercontent.com/147b274365387c91c7741854dcc8780aa56a7286ec190526a8905cbe097277c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726562656c636f64652f77702d68747470)](https://packagist.org/packages/rebelcode/wp-http)

A WordPress HTTP client that complies with the [PSR-7 HTTP Message](https://www.php-fig.org/psr/psr-7/) and [PSR-18 HTTP client](https://www.php-fig.org/psr/psr-18/) standards.

**Note:** This package was written for use in RebelCode's WordPress products only, as a means to mitigate conflicts with other plugins; most notably, those that use [Guzzle](https://github.com/guzzle/guzzle). Feel free to use this package, but please be advised that doing so can cause conflicts, which defeats the purpose of this package.

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

[](#installation)

**With Composer:**

```
composer require rebelcode/wp-http

```

**Without Composer:**

1. Copy the contents of `src` into the directory of your choice
2. Use an autoloader to map the `RebelCode\WordPress\Http` namespace to that directory
3. Consider using [Composer](https://getcomposer.org/) instead

Usage
-----

[](#usage)

**Creating a client instance**

```
use RebelCode\WordPress\Http\WpClient;
use RebelCode\WordPress\Http\WpHandler;
use RebelCode\WordPress\Http\HandlerStack;
use RebelCode\WordPress\Http\Middleware;

/*-----------------------------------------------------------------------------
 * Default configuration.
 * - Uses the `WpHandler`
 * - Uses the `HttpErrorsToExceptions` middleware
 * - Uses the `PrepareBody` middleware
 */

$client = WpClient::createDefault('https://base-url.com/api', [
    'timeout' => 30,
    'redirection' => 3,
]);

/*-----------------------------------------------------------------------------
 * Custom configuration with middleware:
 * - Create the `WpHandler`
 * - Create a `HandlerStack` with the handler and middleware factories
 * - Create the `WpClient` and pass the stack
 */

$wpHandler = new WpHandler([
    'timeout' => 30,
    'redirection' => 3,
]);

$handlerStack = new HandlerStack($wpHandler, [
    Middleware::factory(Middleware\PrepareBody::class)
]);

$client = new WpClient($handlerStack, 'https://base-url.com/api');

/*-----------------------------------------------------------------------------
 * For a zero-middleware configuration, you can simply pass the base handler
 */

$client = new WpClient($wpHandler, 'https://base-url.com/api');
```

**Sending Requests**

The `WpClient` implements the PSR-18 `ClientInterface`. Requests are dispatched using `sendRequest()` method:

```
use RebelCode\WordPress\Http\WpHandler;
use RebelCode\Psr7\Request;

$client = new WpClient(new WpHandler(), 'https://base-url.com/api');

$request = new Request('GET', '/users');
$response = $client->sendRequest($request);
```

Architecture
------------

[](#architecture)

The design and architecture of this package is loosely based on [Guzzle](https://github.com/guzzle/guzzle).

The [`WpClient`](src/WpClient.php) class does not actually use the WordPress HTTP API to send requests. Rather, it delegates the handling of the request to a [`HandlerInterface`](src/HandlerInterface.php) instance. The only thing the client is directly responsible for is resolving relative request URIs using a base URI (if one is given to the client during construction).

Handlers are objects that take a `RequestInterface` instance and return a `ResponseInterface` instance. The [`WpHandler`](src/WpHandler.php), for example, transforms the request into the array of arguments required by the [`wp_remote_request()`](https://developer.wordpress.org/reference/functions/wp_remote_request/) function, calls the function, then transforms the returned value into a `ResponseInterface` instance.

Middleware
----------

[](#middleware)

Middlewares are a special type of `HandlerInterface`: they take a `RequestInterface` and return a `ResponseInterface`.

The key difference is that middlewares do not actually dispatch the request. Instead, they receive a `HandlerInterface`instance during construction and delegate to it by calling `$this->next($request)`.

This allows for multiple middlewares to be chained together, such that the first middleware is given the second middleware, which in turn is given the third middleware, and so on. The last middleware is then given the base handler, typically the `WpClient` instance. This chaining is implemented in the [`HandlerStack`](src/HandlerStack.php), which is also a `HandlerInterface` implementation.

---

Middleware classes may accept additional constructor arguments, as long as a handler argument is accepted and is passed to the parent constructor.

**Example implementation of a middleware**

```
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use RebelCode\WordPress\Http\Middleware;

class MyMiddleware extends Middleware {
    public function __construct(HandlerInterface $handler, $arg1, $arg2) {
        parent::__construct($handler);
        // ...
    }

    /** @inheritDoc*/
    public function handle(RequestInterface $request) : ResponseInterface{
        // Do something with the request
        $newRequest = $request->withHeader('X-Foo', 'Bar');

        // Delegate to the next handler
        $response = $this->next($newRequest);

        // Do something with the response and return it
        return $response->withHeader('X-Baz', 'Qux');
    }
}
```

The middleware can then be given to the `HandlerStack` using a factory function that takes a `HandlerInterface`instance and returns the middleware instance.

```
$stack = new HandlerStack($baseHandler, [
    function ($handler) {
        return new MyMiddleware($handler, $arg1, $arg2);
    }
]);
```

If the first argument of the middleware constructor is the handler, the `Middleware::factory()` helper function can be utilized to reduce boilerplate code. Additional constructor arguments can be passed as the second argument, in an array.

```
$stack = new HandlerStack($baseHandler, [
    Middleware::factory(MyMiddleware::class, [$arg1, $arg2]),
]);
```

###  Health Score

24

—

LowBetter than 35% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

3

Last Release

1700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8036caaa483e3f8a21d0083284bd508f5ada08ad45b790b5075ecff49f09b6b?d=identicon)[rebelcode](/maintainers/rebelcode)

---

Top Contributors

[![mecha](https://avatars.githubusercontent.com/u/5425482?v=4)](https://github.com/mecha "mecha (31 commits)")

---

Tags

httppsr-7clientwordpresspsr-18

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rebelcode-wp-http/health.svg)

```
[![Health](https://phpackages.com/badges/rebelcode-wp-http/health.svg)](https://phpackages.com/packages/rebelcode-wp-http)
```

###  Alternatives

[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2342.1k1](/packages/vultr-vultr-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28132.9k](/packages/phpro-http-tools)[amphp/http-client-psr7

PSR-7 adapter for Amp's HTTP client.

1448.3k3](/packages/amphp-http-client-psr7)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1416.7k5](/packages/chillerlan-php-httpinterface)[zelenin/http-client

PSR-18 compatible HTTP client with middleware support

322.1k](/packages/zelenin-http-client)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

133.0k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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