onassar / PHP-RemoteRequests

PHP HTTP request class (and traits) to provide remote request functionality (including pagination, rate limit lookups and standard 3rd-party search API methods).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP-RemoteRequests

PHP HTTP request class (and traits) to provide remote request functionality (including pagination, rate limit lookups and standard 3rd-party search API methods).

Features include:

  • Requests using cURL
  • Requests using streams
  • Recursive requests
  • Rate limit access
  • Multi-attempts (with sleep calls between attempts)
  • Header access
  • JSON parsing
  • POST requests (currently limited to stream requests)

Requires

Sample Request

$client = new onassar\RemoteRequests\Base();
$url = 'https://example.org';
$client->setURL($url);
$response = $client->get() ?? 'Could not load response';
echo $response;
exit(0);

Sample Request (short)

$client = new onassar\RemoteRequests\Base();
$response = $client->get('https://example.org/') ?? 'Could not load response';
echo $response;
exit(0);

Sample JSON Request

$client = new onassar\RemoteRequests\Base();
$client->setExpectedResponseContentType('application/json');
$url = 'https://example.org/file.json';
$client->setURL($url);
$arr = $client->get() ?? array();
print_r($arr);
exit(0);

Sample JSON Request (short)

$client = new onassar\RemoteRequests\Base();
$client->setExpectedResponseContentType('application/json');
$arr = $client->get('https://example.org/file.json') ?? array();
print_r($arr);
exit(0);

Sample Request Data

$client = new onassar\RemoteRequests\Base();
$url = 'https://example.org';
$client->setURL($url);
$param = 'value';
$requestData = compact('param');
$client->setRequestData($requestData);
$response = $client->get() ?? 'Could not load response';
echo $response;
exit(0);

Sample Request Data (short)

$client = new onassar\RemoteRequests\Base();
$param = 'value';
$requestData = compact('param');
$client->setRequestData($requestData);
$response = $client->get('https://example.org/') ?? 'Could not load response';
echo $response;
exit(0);

Sample cURL Request

$client = new onassar\RemoteRequests\Base();
$client->setRequestApproach('cURL');
$url = 'https://example.org';
$client->setURL($url);
$response = $client->get() ?? 'Could not load response';
echo $response;
exit(0);

Sample cURL Request (short)

$client = new onassar\RemoteRequests\Base();
$client->setRequestApproach('cURL');
$response = $client->get('https://example.org') ?? 'Could not load response';
echo $response;
exit(0);

Todo

  • Support POST calls using the cURL request approach

Related libraries

About

PHP HTTP request class (and traits) to provide remote request functionality (including pagination, rate limit lookups and standard 3rd-party search API methods).

License:MIT License


Languages

Language:PHP 100.0%