PHP code example of someniatko / simple-http-client
1. Go to this page and download the library: Download someniatko/simple-http-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
someniatko / simple-http-client example snippets
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Someniatko\SimpleHttpClient\SimpleHttpClientInterface;
use Someniatko\SimpleHttpClient\SimpleHttpClient;
function doSomething(SimpleHttpClientInterface $httpClient): void
{
$httpClient->sendRequest(
'POST', // HTTP method
'http://example.com/api/user', // URI
[ 'Authorization' => 'basic dXNlcjpwYXNzd29yZA==' ], // headers
'{"name":"foo","permissions":"rwx"}' // body
);
}
/** @var ClientInterface $psr18Client */
/** @var RequestFactoryInterface $psr17RequestFactory */
/** @var StreamFactoryInterface $psr17StreamFactory */
$client = new SimpleHttpClient(
$psr18Client,
$psr17RequestFactory,
$psr17StreamFactory
);
doSomething($client);