PHP code example of hiddeco / laravel-http-adapter

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

    

hiddeco / laravel-http-adapter example snippets


use HiddeCo\HttpAdapter\Facades\HttpAdapter;

$request = HttpAdapter::get('http://awesome.com');
$body = $request->getBody();
// and you're done

use HiddeCo\HttpAdapter\Facades\HttpAdapter;

$request = HttpAdapter::connection('alternative')->get('http://awesome.com');

use HiddeCo\HttpAdapter\Facades\HttpAdapter;

HttpAdapter::connection('main')->get('http://awesome.com');
HttpAdapter::get('http://awesome.com');
HttpAdapter::connection()->get('http://awesome.com');
// are all the same because 

HttpAdapter::getDefaultConnection();
// returns 'main' as set in the configuration file

HttpAdapter::setDefaultConnection('alternative');
// the 'alternative' connection is now the default connection

use HiddeCo\HttpAdapter\HttpAdapterManager;

class Foo
{
	protected $httpadapter;
	
	public function __construct(HttpAdapterManager $httpadapter)
	{
		$this->httpadapter;
	}
	
	public function bar()
	{
		$this->httpadapter->get('http://awesome.com');
	}
}

use Ivory\HttpAdapter\Event\Events;
use Ivory\HttpAdapter\Event\PostSendEvent;

Event::listen(Events::POST_SEND, function (PostSendEvent $event) {
	Log::info("A request was made");
});