34 lines
993 B
PHP
34 lines
993 B
PHP
<?php declare(strict_types=1);
|
|
// HttpClient.php
|
|
// Created: 2024-11-16
|
|
// Updated: 2024-11-16
|
|
|
|
namespace Flashii\Http;
|
|
|
|
use InvalidArgumentException;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* Provides a common interface for making HTTP clients.
|
|
*/
|
|
interface HttpClient {
|
|
/**
|
|
* Creates a HTTP request object.
|
|
*
|
|
* @param string $method Desired request method.
|
|
* @param string $url Target URL.
|
|
* @throws RuntimeException If the request could not be initialised.
|
|
* @return HttpRequest
|
|
*/
|
|
function createRequest(string $method, string $url): HttpRequest;
|
|
|
|
/**
|
|
* Sends a HTTP request and returns a HTTP response.
|
|
*
|
|
* @param HttpRequest $request Request to send.
|
|
* @throws InvalidArgumentException If $request is not understood by the HttpClient implementation.
|
|
* @throws RuntimeException If the HTTP request failed in an unexpected way.
|
|
* @return HttpResponse
|
|
*/
|
|
function sendRequest(HttpRequest $request): HttpResponse;
|
|
}
|