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.
Table of Contents
Methods
- delete() : mixed
- Perform a DELETE request.
- get() : mixed
- Perform a GET request.
- patch() : mixed
- Perform a PATCH request.
- post() : mixed
- Perform a POST request.
- put() : mixed
- Perform a PUT request.
- set_authorization_bearer() : self
- Helper to set Bearer Token authorization.
- set_content_type() : self
- Set the Content-Type header.
- set_header() : self
- Add a custom header to the request.
Methods
delete()
Perform a DELETE request.
public
delete(string $uri[, array<string|int, mixed> $query = [] ]) : mixed
Parameters
- $uri : string
- $query : array<string|int, mixed> = []
get()
Perform a GET request.
public
get(string $uri[, array<string|int, mixed> $query = [] ]) : mixed
Parameters
- $uri : string
-
Relative or absolute URL
- $query : array<string|int, mixed> = []
-
Query string parameters
Return values
mixed —Decoded JSON (array/object) or raw string body
patch()
Perform a PATCH request.
public
patch(string $uri[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $uri : string
- $data : array<string|int, mixed> = []
post()
Perform a POST request.
public
post(string $uri[, array<string|int, mixed> $data = [] ][, bool $as_json = true ]) : mixed
Parameters
- $uri : string
- $data : array<string|int, mixed> = []
-
Body data
- $as_json : bool = true
-
If true, sends as application/json. If false, as x-www-form-urlencoded.
put()
Perform a PUT request.
public
put(string $uri[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $uri : string
- $data : array<string|int, mixed> = []
set_authorization_bearer()
Helper to set Bearer Token authorization.
public
set_authorization_bearer(string $token) : self
Parameters
- $token : string
Return values
self —Fluent interface
set_content_type()
Set the Content-Type header.
public
set_content_type(string $content_type) : self
Parameters
- $content_type : string
Return values
self —Fluent interface
set_header()
Add a custom header to the request.
public
set_header(string $key, string $value) : self
Parameters
- $key : string
- $value : string
Return values
self —Fluent interface