PHP code example of simplon / http

1. Go to this page and download the library: Download simplon/http 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/ */

    

simplon / http example snippets


use Psr\Http\Message\ResponseInterface;
use Simplon\Http\Adapter\GuzzleHttp;
use Simplon\Http\HttpInterface;
use Simplon\Http\Strategies\JsonRequestStrategy;

//
// some class
//

class SomeHttp
{
    /**
     * @var HttpInterface
     */
    private $http;

    /**
     * @param HttpInterface $http
     */
    public function __construct(HttpInterface $http)
    {
        $this->http = $http;
    }

    /**
     * @return ResponseInterface
     * @throws Exception
     * @throws \Http\Client\Exception
     */
    public function register(): ResponseInterface
    {
        $request = $this->http->buildRequest('POST', 'http://someapi.com/1.0/register');
        JsonRequestStrategy::create($request, ['token' => '00RVS2CI7K1S']);

        return $this->http->sendRequest($request);
    }
}

$foo = new SomeHttp(new GuzzleHttp());
$response = $foo->register();

//
// print response
//

var_dump($response->getBody()->getContents());