Simple HTTP client for PSR-18 requests — the NixPHP way.
This plugin provides a lightweight and dependency-free implementation
of the Psr\Http\Client\ClientInterface, using native PHP streams.
🧩 Part of the official NixPHP plugin collection. Perfect for internal API calls, simple integrations, and testing purposes.
- ✅ Implements
Psr\Http\Client\ClientInterface - ✅ No cURL, no external dependencies — pure PHP
- ✅ Supports custom handlers for testing/mocking
- ✅ Optional SSL verification toggle via config
- ✅ Integrates cleanly via
client()helper
composer require nixphp/clientThat’s it. The plugin will be autoloaded and ready to use.
use Nyholm\Psr7\Request;
$request = new Request('GET', 'https://example.com/api');
$response = client()->sendRequest($request);
echo $response->getStatusCode();
echo (string) $response->getBody();You can also pass a custom handler (e.g. for unit tests):
$response = client()->sendRequest($request, function($url, $opts) {
return ['{"mock":true}', ['HTTP/1.1 200 OK']];
});Disable SSL peer verification (e.g. for local dev):
// app/config.php
return [
'ssl_verify' => false
];This disables verify_peer, verify_peer_name, and allows self-signed certs.
- Uses
file_get_contents()with PHP stream context. - Parses raw headers into a PSR-7-compatible
Responseobject. - Default response class:
Nyholm\Psr7\Response - Automatically included via
client()helper.
nixphp/framework>= 1.0nyholm/psr7>= 1.0 (used for PSR-7 implementation)
MIT License.
