Skip to content

nixphp/client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

NixPHP Client Plugin for simple http requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages