Documentation

HttpClient
in package

Provides simple methods to make GET & POST HTTP requests.

Wrapper around GuzzleHttp\Client.

Tags
see
Client
author

Aberdeener

version
2.0.0-pr13
license

MIT

Table of Contents

Properties

$_error  : string
$_response  : ResponseInterface|null

Methods

contents()  : string
Get the response body.
createClient()  : Client
Make a new Guzzle Client instance and attach it to the debug bar to display requests.
delete()  : HttpClient
Make a DELETE request to a URL.
get()  : HttpClient
Make a GET request to a URL.
getError()  : string
Get the error message.
getStatus()  : int
Get the response HTTP status code.
hasError()  : bool
Check if the response has an error.
json()  : mixed
Get the response body as a decoded JSON object.
patch()  : HttpClient
Make a PATCH request to a URL.
post()  : HttpClient
Make a POST request to a URL.
put()  : HttpClient
Make a PUT request to a URL.
__construct()  : mixed

Properties

$_response

private ResponseInterface|null $_response

Methods

contents()

Get the response body.

public contents() : string
Return values
string

The response body

createClient()

Make a new Guzzle Client instance and attach it to the debug bar to display requests.

public static createClient([array<string|int, mixed> $options = [] ]) : Client
Parameters
$options : array<string|int, mixed> = []

Options to provide Guzzle instance.

Return values
Client

New Guzzle instance.

delete()

Make a DELETE request to a URL.

public static delete(string $url, string|array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : HttpClient

Failures will automatically be logged along with the error.

Parameters
$url : string

URL to send request to.

$data : string|array<string|int, mixed>

JSON request body to attach to request, or array of key value pairs if form-urlencoded.

$options : array<string|int, mixed> = []

Options to set with the GuzzleClient.

Return values
HttpClient

New HttpClient instance.

get()

Make a GET request to a URL.

public static get(string $url[, array<string|int, mixed> $options = [] ]) : HttpClient

Failures will automatically be logged along with the error.

Parameters
$url : string

URL to send request to.

$options : array<string|int, mixed> = []

Options to set with the GuzzleClient.

Return values
HttpClient

New HttpClient instance.

getError()

Get the error message.

public getError() : string
Return values
string

The error message

getStatus()

Get the response HTTP status code.

public getStatus() : int
Return values
int

The response code

hasError()

Check if the response has an error.

public hasError() : bool
Return values
bool

Whether the response has an error or not

json()

Get the response body as a decoded JSON object.

public json([bool $assoc = false ]) : mixed
Parameters
$assoc : bool = false

Whether to decode the JSON as a PHP array if true or PHP object.

Return values
mixed

The response body

patch()

Make a PATCH request to a URL.

public static patch(string $url, string|array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : HttpClient

Failures will automatically be logged along with the error.

Parameters
$url : string

URL to send request to.

$data : string|array<string|int, mixed>

JSON request body to attach to request, or array of key value pairs if form-urlencoded.

$options : array<string|int, mixed> = []

Options to set with the GuzzleClient.

Return values
HttpClient

New HttpClient instance.

post()

Make a POST request to a URL.

public static post(string $url, string|array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : HttpClient

Failures will automatically be logged along with the error.

Parameters
$url : string

URL to send request to.

$data : string|array<string|int, mixed>

JSON request body to attach to request, or array of key value pairs if form-urlencoded.

$options : array<string|int, mixed> = []

Options to set with the GuzzleClient.

Return values
HttpClient

New HttpClient instance.

put()

Make a PUT request to a URL.

public static put(string $url, string|array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : HttpClient

Failures will automatically be logged along with the error.

Parameters
$url : string

URL to send request to.

$data : string|array<string|int, mixed>

JSON request body to attach to request, or array of key value pairs if form-urlencoded.

$options : array<string|int, mixed> = []

Options to set with the GuzzleClient.

Return values
HttpClient

New HttpClient instance.

__construct()

private __construct(ResponseInterface|null $response, string $error) : mixed
Parameters
$response : ResponseInterface|null
$error : string

        
On this page

Search results