class http_client_adapter implements http_client_interface

internal  
 

Modern HTTP Client wrapper using Guzzle.

Serves as the standard HTTP client for the entire MIDDAG ecosystem. Automatically handles Moodle's proxy settings and User-Agent rules.

Usage: $client = new http_client_adapter('https://api.example.com'); $data = $client->set_authorization_bearer($token)->get('/users');

Methods

__construct(string $base_uri = '')

Initializes the client with default Moodle settings (timeout, proxy, user-agent).

set_header(string $key, string $value)

Sets a custom header for subsequent requests.

set_authorization_bearer(string $token)

Sets the Authorization Bearer token header.

set_content_type(string $content_type)

Sets the Content-Type header.

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

Performs a synchronous GET request.

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

Performs a synchronous POST request.

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

Performs a synchronous PUT request with JSON body.

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

Performs a synchronous PATCH request with JSON body.

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

Performs a synchronous DELETE request.

Details

at line 54
__construct(string $base_uri = '')

Initializes the client with default Moodle settings (timeout, proxy, user-agent).

Parameters

string $base_uri

optional base URI for all requests

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

Sets a custom header for subsequent requests.

Parameters

string $key
string $value

Return Value

http_client_interface

Fluent interface

at line 111
http_client_interface set_authorization_bearer(string $token)

Sets the Authorization Bearer token header.

Parameters

string $token

Return Value

http_client_interface

Fluent interface

at line 123
http_client_interface set_content_type(string $content_type)

Sets the Content-Type header.

Parameters

string $content_type

Return Value

http_client_interface

Fluent interface

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

Performs a synchronous 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 150
mixed post(string $uri, array $data = [], bool $as_json = true)

Performs a synchronous 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 165
mixed put(string $uri, array $data = [])

Performs a synchronous PUT request with JSON body.

Parameters

string $uri
array $data

Return Value

mixed

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

Performs a synchronous PATCH request with JSON body.

Parameters

string $uri
array $data

Return Value

mixed

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

Performs a synchronous DELETE request.

Parameters

string $uri
array $query

Return Value

mixed