ClassGo
HTTP\Client
class HTTP\Client {
- public function __construct(mixed $options);
- public function get(string $url): object;
- public function parallel(mixed $requests): array;
- public function post(string $url, string ...$body): object;
- public function send(object $request): object;
}
Description
HTTP\Client sends requests, one at a time with send() or all at once with parallel(). It takes its settings as an associative array, and with no argument builds a client with a 30 second timeout that follows redirects.
HTTP\Client is a class phpscript declares.
$object = new HTTP\Client($options);
Methods
public function get(string $url): object-
get sends a GET request to $url and returns the response.
The go method
Get. public function parallel(mixed $requests): array-
parallel sends every request in $requests at once and returns the responses under the same keys and the call takes as long as the slowest request rather than the sum. $requests is an array of HTTP\Request keyed by a name the script chooses, each bounded by the client's timeout.
One request failing does not fail the others and does not throw: that response reports $response->ok() as false and $response->err() as the reason, and a script sees every outcome. A throw means the argument is no array of requests.
The go method
Parallel. public function post(string $url, string ...$body): object-
post sends a POST request to $url with $body and returns the response.
The go method
Post. public function send(object $request): object-
send sends $request and returns the response. A transport failure or a timeout throws; an HTTP error status does not and check $response->status().
The go method
Send.
Binding
- The go type
github.com/titpetric/phpscript/stdlib/http.Client. - Registered by the package
github.com/titpetric/phpscript/stdlib/http. - Built on
net/http.Client.