interface http_client_interface

Contract for the Framework's HTTP Client.

Provides a standardized, fluent interface for making HTTP requests. Implementations must handle low-level transport (Guzzle/Curl), proxy settings, and Moodle's User-Agent compliance automatically.

Methods

set_header(string $key, string $value)

Add a custom header to the request.

set_authorization_bearer(string $token)

Helper to set Bearer Token authorization.

set_content_type(string $content_type)

Set the Content-Type header.

mixed
get(string $uri, array $query = [])

Perform a GET request.

mixed
post(string $uri, array $data = [], bool $as_json = true)

Perform a POST request.

mixed
put(string $uri, array $data = [])

Perform a PUT request.

mixed
patch(string $uri, array $data = [])

Perform a PATCH request.

mixed
delete(string $uri, array $query = [])

Perform a DELETE request.

Details

at line 37
http_client_interface set_header(string $key, string $value)

Add a custom header to the request.

Parameters

string $key
string $value

Return Value

http_client_interface

Fluent interface

at line 46
http_client_interface set_authorization_bearer(string $token)

Helper to set Bearer Token authorization.

Parameters

string $token

Return Value

http_client_interface

Fluent interface

at line 55
http_client_interface set_content_type(string $content_type)

Set the Content-Type header.

Parameters

string $content_type

Return Value

http_client_interface

Fluent interface

at line 65
mixed get(string $uri, array $query = [])

Perform a GET request.

Parameters

string $uri

Relative or absolute URL

array $query

Query string parameters

Return Value

mixed

Decoded JSON (array/object) or raw string body

at line 76
mixed post(string $uri, array $data = [], bool $as_json = true)

Perform a POST request.

Parameters

string $uri
array $data

Body data

bool $as_json

If true, sends as application/json. If false, as x-www-form-urlencoded.

Return Value

mixed

at line 86
mixed put(string $uri, array $data = [])

Perform a PUT request.

Parameters

string $uri
array $data

Return Value

mixed

at line 96
mixed patch(string $uri, array $data = [])

Perform a PATCH request.

Parameters

string $uri
array $data

Return Value

mixed

at line 106
mixed delete(string $uri, array $query = [])

Perform a DELETE request.

Parameters

string $uri
array $query

Return Value

mixed