nixphp/client

NixPHP Client Plugin for simple http requests.

Maintainers

Details

github.com/nixphp/client

Source

Issues

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:nixphp-plugin

dev-main 2025-07-26 17:42 UTC

This package is auto-updated.

Last update: 2025-07-26 17:42:57 UTC


README

Logo

NixPHP Client Plugin

← Back to NixPHP

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.0
  • nyholm/psr7 >= 1.0 (used for PSR-7 implementation)

πŸ“„ License

MIT License.