1. Go to this page and download the library: Download eypsilon/curler 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/ */
eypsilon / curler example snippets
use Many\Http\Curler;
// Simple GET request
$response = (new Curler())->get('https://api.example.com/users');
echo $response->getBody();
// With authentication and JSON
$response = (new Curler())
->authBearer('your-token-here')
->withJson(['name' => 'John Doe'])
->post('https://api.example.com/users');
// With callbacks and validation
$response = (new Curler())
->validate(fn($data) => !empty($data), 'Data not empty')
->jsonDecode()
->through(fn($data) => array_merge($data, ['processed' => true]))
->jsonEncode(JSON_PRETTY_PRINT)
->get('https://api.example.com/data');
Curler::setConfig([
// Default URL prefix (auto-applied to relative URLs)
'default_url' => 'https://api.example.com',
// Default headers sent with every request
'default_headers' => [
'X-App-Name' => 'MyApp',
'Accept' => 'application/json',
],
// Default CURL options
'default_options' => [
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => 'MyApp/1.0',
],
// Features
'enable_exceptions' => true, // Throw exceptions on errors
'enable_meta' => true, // Include meta data in response
'enable_history' => true, // Track request history
// Image conversion (MIME types to convert to data URIs)
'image_to_data' => ['image/jpeg', 'image/png', 'image/webp'],
// Retry configuration
'retry_attempts' => 3,
'retry_delay_ms' => 100,
'retry_on_status' => [429, 500, 502, 503, 504],
// Date format for timestamps
'date_format' => 'Y-m-d H:i:s.u',
]);
// GET
$response = (new Curler())->get('https://api.example.com/users');
// GET with query parameters
$response = (new Curler())->get('https://api.example.com/users', [
'page' => 1,
'limit' => 10
]);
// POST with form data
$response = (new Curler())
->withForm(['name' => 'John', 'email' => '[email protected]'])
->post('https://api.example.com/users');
// POST with JSON
$response = (new Curler())
->withJson(['name' => 'John', 'email' => '[email protected]'])
->post('https://api.example.com/users');
// PUT, PATCH, DELETE
$response = (new Curler())
->withJson(['name' => 'Jane'])
->put('https://api.example.com/users/123');
$response = (new Curler())->delete('https://api.example.com/users/123');
// Simple QUERY with JSON body
$response = (new Curler())->query(
'https://api.example.com/search',
['query' => 'php', 'filters' => ['status' => 'active']]
);
// QUERY with GraphQL
$response = (new Curler())->queryGraphQL(
'https://api.example.com/graphql',
'query GetUser($id: ID!) { user(id: $id) { name email } }',
['id' => '123']
);
// QUERY with URL parameters + body
$response = (new Curler())->query(
'https://api.example.com/search',
['query' => 'php'],
['page' => 1, 'limit' => 10] // URL query params
);
// Basic Auth
$response = (new Curler())
->authBasic('username', 'password')
->get('https://api.example.com/protected');
// Bearer Token
$response = (new Curler())
->authBearer('your-token-here')
->get('https://api.example.com/protected');
// Digest Auth
$response = (new Curler())
->authDigest('username', 'password')
->get('https://api.example.com/protected');
// API Key (custom header)
$response = (new Curler())
->authApiKey('your-api-key', 'X-API-Key')
->get('https://api.example.com/protected');
// Set headers
$response = (new Curler())
->withHeader('X-Custom', 'value')
->withHeaders([
'X-Header-1' => 'value1',
'X-Header-2' => 'value2',
])
->get('https://api.example.com');
// Set query parameters (chainable)
$response = (new Curler())
->url('https://api.example.com/users')
->query(['page' => 1, 'limit' => 10])
->mergeQuery(['sort' => 'desc'])
->get();
$response = (new Curler())
// Validate first
->validate(fn($data) => !empty($data), 'Data not empty')
->validate(fn($data) => Curler::isJson($data), 'Must be JSON')
// Transform
->jsonDecode()
->through(fn($data) => array_merge($data, ['processed_at' => date('c')]))
->through(fn($data) => array_filter($data))
->jsonEncode(JSON_PRETTY_PRINT)
// Final validation
->validate(fn($data) => Curler::isJson($data), 'Final must be JSON')
->get('https://api.example.com/data');