The request()
function allows to make HTTP requests easily. It performs HTTP
request and returns an instance of
Symfony\Contracts\HttpClient\ResponseInterface
:
use Castor\Attribute\AsTask;
use function Castor\io;
use function Castor\request;
#[AsTask()]
function foo()
{
io()->writeln(request('GET', 'https://example.org')->getContent());
}
If you need to have a full control on the HTTP client, you can access the
HttpClientInterface
directly with the http_client()
function:
use Castor\Attribute\AsTask;
use function Castor\http_client;
#[AsTask()]
function foo()
{
$client = http_client()
->withOptions([
'verify_peer' => false,
'timeout' => 10,
])
;
}
You can check the Symfony documentation for more information about this component and how to use it.