The psr-18 implementation for HTTP Clients

1.0.0 2022-06-18 22:32 UTC

This package is auto-updated.

Last update: 2023-05-20 15:01:55 UTC


This is a implementation of psr-18 of php-fig

Basic usage

To get a simple request

use Dadapas\Http\Client as HttpClient;
use Dadapas\Http\Request;
use Dadapas\Http\Exception\HttpException;

try {
	$client = new HttpClient;

	// Make a get request to google
	$request = new Request('GET', "")
		->withHeader('Content-Type', 'text/html');

	// Return the response to the $response variable
	$response = $client->sendRequest($request);

} catch (HttpException $e) {

	echo $e->getMessage();

Method of response class are

$response->status();   // Ok
$response->code() ;    // 200
$response->json();     // Return an array of application empty array instead
$response->toString(); // to get the response to string

You can then pick one of the implementations of the interface to get a logger.

If you want to implement the interface, you can require this package and implement Psr\Http\Message\RequestInterface, Psr\Http\Message\ResponseInterface, Psr\Http\Message\StreamInterface, Psr\Http\Message\UriInterface and in your code. Please read the PSR-7 http messages and PSR-18 http client for details.


For making a test just

composer test


The licence is MIT for more details click here