PHP code example of iamirnet / curl

1. Go to this page and download the library: Download iamirnet/curl 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/ */

    

iamirnet / curl example snippets



$service = new iAmirNet\Curl\iCurlService('https://api.example.com', ['Authorization' => 'Bearer token']);

$service = new iAmirNet\Curl\iCurlService('https://api.example.com', ['Authorization' => 'Bearer token']);

$response = $service->get('/endpoint', ['param1' => 'value1']);
echo $response;

$data = ['key' => 'value'];
$response = $service->post('/endpoint', $data);
echo $response;

$data = ['key' => 'newValue'];
$response = $service->put('/endpoint', [], $data);
echo $response;

$response = $service->delete('/endpoint');
echo $response;

$response = iAmirNet\Curl\iCurl::get('https://api.example.com/data', ['key' => 'value'], ['Authorization' => 'Bearer token']);
if ($response['status']) {
    print_r($response['response']);
} else {
    echo "Error: " . $response['message'];
}

$data = ['name' => 'John Doe', 'email' => '[email protected]'];
$response = iAmirNet\Curl\iCurl::post('https://api.example.com/users', [], $data, ['Content-Type' => 'application/json']);
if ($response['status']) {
    echo "User created successfully!";
} else {
    echo "Error: " . $response['message'];
}

$data = ['name' => 'Jane Doe'];
$response = iAmirNet\Curl\iCurl::put('https://api.example.com/users/1', [], $data, ['Content-Type' => 'application/json']);
if ($response['status']) {
    echo "User updated successfully!";
} else {
    echo "Error: " . $response['message'];
}

$response = iAmirNet\Curl\iCurl::delete('https://api.example.com/users/1', [], [], ['Authorization' => 'Bearer token']);
if ($response['status']) {
    echo "User deleted successfully!";
} else {
    echo "Error: " . $response['message'];
}

$response = iAmirNet\Curl\iCurl::download(
    'https://files.example.com',
    '/path/to/file.zip',
    '/local/storage/file.zip',
    [],
    null,
    ['Authorization' => 'Bearer token'],
    'GET'
);

if ($response['status']) {
    echo "File downloaded to: " . $response['storage'];
} else {
    echo "Download failed: " . $response['message'];
}

$url = 'https://example.com/resource';
if (iAmirNet\Curl\iCurl::exists($url)) {
    echo "Resource exists!";
} else {
    echo "Resource does not exist.";
}

$jsonString = '{"name":"John", "age":30}';
$decoded = iAmirNet\Curl\iCurl::json_decode($jsonString);
print_r($decoded);

$jsonString = '{"name":"John", "age":30}';
if (iAmirNet\Curl\iCurl::is_json($jsonString)) {
    echo "Valid JSON!";
} else {
    echo "Invalid JSON!";
}

i_curl(string $base, string $url, array $params = [], $data = null, array $headers = [], string $method = 'GET', array $options = [])

i_curl_get(string $base, string $url, array $params = [], array $headers = [], array $options = [])

i_curl_post(string $base, string $url, $data = null, array $params = [], array $headers = [], array $options = [])

i_curl_delete(string $base, string $url, $data = null, array $params = [], array $headers = [], array $options = [])

i_curl_put(string $base, string $url, $data = null, array $params = [], array $headers = [], array $options = [])

i_curl_dl(string $base, string $url, string $out, array $params = [], $data = null, array $headers = [], string $method = 'GET', array $options = [])

i_curl_exists(string $base, string $url = '')

sudo apt-get install curl php-curl
curl -s http://getcomposer.org/installer | php
php composer.phar install

php composer.phar