webclient/webclient

simple HTTP client without cURL dependency

v1.0.4 2022-08-13 22:01 UTC

This package is not auto-updated.

Last update: 2024-04-21 07:04:59 UTC


README

Latest Stable Version Total Downloads License PHP

webclient/webclient

Simple HTTP client without cURL dependency.

Install

Install this package, your favorite psr-7 implementation and your favorite psr-17 implementation.

composer require webclient/webclient:^1.0

Using

<?php

use Webclient\Http\Webclient;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

/** 
 * @var ResponseFactoryInterface $responseFactory
 * @var StreamFactoryInterface $streamFactory
 */
$http = new Webclient($responseFactory, $streamFactory);

/** @var RequestInterface $request */
$response = $http->sendRequest($request);

$code = $response->getStatusCode();
$phrase = $response->getReasonPhrase();
$headers = $response->getHeaders();
$someHeader = $response->getHeader('Content-Type');

$body = $response->getBody()->__toString();

Extensions