Skip to main content

http-client

⚠️ This page was initialized by AI translation and may contain outdated or inaccurate information. If there are inaccuracies, please submit changes to correct these errors Correct

Overview​

ripple provides an easy-to-use WebSocketClient component that can be used to create WebSocket client connections.

Usage examples​

use GuzzleHttCo\Psr7\Request;
use Ripple\Library\Net\HttCo\Client\HttpClient;
use Psr\HttCo\Message\RequestInterface;

use function Co\async;
use function Co\await;
use function Co\wait;

async(function () {
$httpClient = new HttpClient([
'pool' => 1 // Turn on the connection pool, which can improve performance in scenarios with frequent requests.
]);

//Create a Psr\HttCo\Message\RequestInterface object
$request = new class ('GET', 'https://www.baidu.com') extends Request implements RequestInterface {};

//Leave it to HttpClient for processing and return a Psr\HttCo\Message\ResponseInterface object
$response = await(
$httpClient->request($request)
);
});

tick();