Navigation Menu

Skip to content

phpwebclient/webclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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