nixphp / client
NixPHP Client Plugin for simple http requests.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:nixphp-plugin
Requires
- php: >=8.3
- nixphp/framework: dev-main
- nyholm/psr7: ^1.8
- psr/http-client: ^1.0
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
- phpunit/phpunit: ^12.1
This package is auto-updated.
Last update: 2025-07-26 17:42:57 UTC
README
nixphp/client
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.
π¦ Features
- β
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
π₯ Installation
composer require nixphp/client
Thatβs it. The plugin will be autoloaded and ready to use.
π Usage
βοΈ Send a PSR-7 request
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']]; });
βοΈ Configuration
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.
π Internals
- Uses
file_get_contents()
with PHP stream context. - Parses raw headers into a PSR-7-compatible
Response
object. - Default response class:
Nyholm\Psr7\Response
- Automatically included via
client()
helper.
β Requirements
nixphp/framework
>= 1.0nyholm/psr7
>= 1.0 (used for PSR-7 implementation)
π License
MIT License.