PHP code example of abollinger / http
1. Go to this page and download the library: Download abollinger/http library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abollinger / http example snippets
use Abollinger\Http\Client;
$response = Client::get([
'url' => 'https://api.example.com/data',
'headers' => ['Authorization' => 'Bearer token123']
]);
$response = Client::post([
'url' => 'https://api.example.com/data',
'data' => ['key' => 'value'],
'headers' => ['Content-Type' => 'application/json']
]);
$headers = Client::getHeaders([
'url' => 'https://api.example.com/data'
]);
$headers = Client::getNormalizedHeaders([
'url' => 'https://api.example.com/data'
]);
[
'status' => 200, // HTTP status code
'headers' => ['Content-Type' => 'application/json', ...], // Parsed headers
'body' => ['data' => '...'] // Parsed body (or ['raw' => '...'] if not JSON)
]
if (isset($response['error'])) {
echo "Error: " . $response['error'];
}
use Abollinger\Http\Client;
// GET request
$data = Client::get(['url' => 'https://api.example.com/users']);
// POST request with custom headers
$result = Client::post([
'url' => 'https://api.example.com/users',
'data' => ['name' => 'John Doe'],
'headers' => ['Authorization' => 'Bearer token123']
]);