HelPHP

Rest
in package

Tags
class

Rest

Simple REST client for forging HTTP requests (GET, POST, PUT, DELETE) with support for custom headers, file uploads (multipart/form-data), JSON payloads, and URL-encoded data. Uses PHP streams (no cURL required).

Table of Contents

Properties

$command  : string
$command_type  : string
$data  : array<string|int, mixed>
$encode  : bool
$files  : array<string|int, mixed>|false
$header  : array<string|int, mixed>
$header_array  : bool
$json  : bool

Methods

__construct()  : mixed
Rest constructor.
client_request()  : string
Executes the HTTP request to the API endpoint.

Properties

$command

public string $command

The command or endpoint to call.

$command_type

public string $command_type

HTTP method to use (GET, POST, PUT, DELETE).

$data

public array<string|int, mixed> $data

Data to send with the request (query or body).

$encode

public bool $encode

If true, data is URL-encoded for POST/PUT.

$files

public array<string|int, mixed>|false $files

Files to send (for multipart/form-data).

$header

public array<string|int, mixed> $header

Custom headers to include in the request.

$header_array

public bool $header_array

If true, headers are sent as an array (for stream context).

$json

public bool $json

If true, data is sent as JSON.

Methods

__construct()

Rest constructor.

public __construct(string $apiurl, string $command_type, string $command[, array<string|int, mixed>|false $data = false ][, array<string|int, mixed>|false $header = false ][, bool $echo = false ][, bool $encode = true ][, array<string|int, mixed>|false $files = false ][, bool $json = false ][, bool $header_array = false ]) : mixed
Parameters
$apiurl : string

The base API URL.

$command_type : string

HTTP method (GET, POST, PUT, DELETE).

$command : string

The endpoint or command to call.

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

Data to send (default: empty array).

$header : array<string|int, mixed>|false = false

Headers to send (default: empty array).

$echo : bool = false

If true, echoes the response directly.

$encode : bool = true

If true, URL-encode data (default: true).

$files : array<string|int, mixed>|false = false

Files to send (for multipart/form-data).

$json : bool = false

If true, send data as JSON.

$header_array : bool = false

If true, headers are sent as an array.

client_request()

Executes the HTTP request to the API endpoint.

public client_request() : string

Handles GET, POST, PUT, DELETE methods, custom headers, file uploads, and JSON payloads. Uses PHP streams (fopen) for the request.

Return values
string

The response body from the API, or an error message.


        
On this page

Search results