{"id":15022306,"url":"https://github.com/eypsilon/curler","last_synced_at":"2026-03-27T02:42:57.736Z","repository":{"id":49803128,"uuid":"518117793","full_name":"eypsilon/Curler","owner":"eypsilon","description":"Another one CURLs the dust","archived":false,"fork":false,"pushed_at":"2023-03-10T11:47:06.000Z","size":44,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T07:11:31.994Z","etag":null,"topics":["api","curl","curlphp","php"],"latest_commit_sha":null,"homepage":"https://curler-eypsilon.vercel.app/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eypsilon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-26T15:30:47.000Z","updated_at":"2023-03-19T17:45:09.000Z","dependencies_parsed_at":"2024-09-21T11:01:06.139Z","dependency_job_id":null,"html_url":"https://github.com/eypsilon/Curler","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"58f954af7c7934b8fcd26cd0fd8569e25f2ee4a8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eypsilon%2FCurler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eypsilon%2FCurler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eypsilon%2FCurler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eypsilon%2FCurler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eypsilon","download_url":"https://codeload.github.com/eypsilon/Curler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248566889,"owners_count":21125743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","curl","curlphp","php"],"created_at":"2024-09-24T19:57:46.423Z","updated_at":"2026-03-27T02:42:57.702Z","avatar_url":"https://github.com/eypsilon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MANY/CURLER | Another one CURLs the dust\n\nThis class is written to simplify the use of CURL in PHP using chained methods and more rememberable names.\n\nI needed a simple way to explore the Shopware API (v6.*) via http and the Bearer token authentication scheme, but haven't found, what i was looking for to do it, so i ended up with this one. It does nothing new at all, nothing exciting, just simple Requests to URLs and Endpoints like you would expect, but a bit prettier than CURL itself.\n\nSee [./public/index.php](./public/index.php) for examples or check the livedemo on [Vercel](https://curler-eypsilon.vercel.app/).\n\n```bash\ncomposer require eypsilon/curler\n```\n\n```php\nuse Many\\Http\\Curler;\n\n/**\n * @var array Simple get\n */\n$c = (new Curler)-\u003eget('https://example.com/');\nprint $c['response'];\n\n/**\n * @var string with Auth creds\n */\n$xc = (new Curler)\n    -\u003eauthAny('user', 'pass')\n    -\u003epost(\n        json_encode([\n            'lorem_ipsum' =\u003e 'Dolor Sit Amet',\n        ])\n    )\n    -\u003eresponseOnly() // returns $xc['response']\n    -\u003eexec('/api/usr');\nprint $xc;\n```\n\n\n## Usage\n\n```php\n/**\n * @var array Set Configs and Defaults\n */\nCurler::setConfig([\n    'response_only' =\u003e false, // returns the response content as is\n    'curl_trace'    =\u003e false, // track requests, (GET) Curl::getCurlTrace()\n    'exceptions'    =\u003e false, // enable Exceptions\n    'meta'          =\u003e false, // enable meta data\n    'request_info'  =\u003e false, // [getallheaders(), $_SERVER] in 'meta'\n    'curl_info'     =\u003e false, // CURL generated infos about the request in 'meta'\n\n    // Default URL, will be prefixed to each request URL, disable with: -\u003edisableDefaultUrl()\n    'default_url'   =\u003e null,  // 'https://example.com'\n    'date_format'   =\u003e 'Y-m-d H:i:s.u',\n\n    // Convert images to valid data strings (no defaults defined)\n    'image_to_data' =\u003e [], // 'image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/x-icon', 'image/svg+xml', ...\n\n    // Send default headers (no defaults defined)\n    'default_header' =\u003e [], // 'x-powered-by' =\u003e 'Many/Curler',\n\n    // Add/overwrite CURL default options, see Curl::getOptions()\n    'default_options' =\u003e [\n        CURLINFO_HEADER_OUT =\u003e false,\n        CURLOPT_HTTP_VERSION =\u003e CURL_HTTP_VERSION_NONE,\n        CURLOPT_URL =\u003e null,\n        CURLOPT_CUSTOMREQUEST =\u003e 'GET',\n        CURLOPT_HEADER =\u003e false,\n        CURLOPT_HTTPHEADER =\u003e [],\n        CURLOPT_POST =\u003e false,\n        CURLOPT_POSTFIELDS =\u003e null, // (string) http_build_query($str)\n        CURLOPT_SSL_VERIFYHOST =\u003e 2,\n        CURLOPT_SSL_VERIFYPEER =\u003e true,\n        CURLOPT_RETURNTRANSFER =\u003e true,\n        CURLOPT_VERBOSE =\u003e true,\n        CURLOPT_AUTOREFERER =\u003e true,\n        CURLOPT_FOLLOWLOCATION =\u003e true,\n        CURLOPT_MAXREDIRS =\u003e 10,\n        CURLOPT_CONNECTTIMEOUT =\u003e 90,\n        CURLOPT_TIMEOUT =\u003e 90,\n        CURLOPT_ENCODING =\u003e 'gzip',\n        CURLOPT_USERAGENT =\u003e 'Many/Curler',\n    ],\n\n    // Set a callback function, that gets fired after first curl_exec(), eg. for logging\n    'default_callback' =\u003e [], // =\u003e ['print_r', true],\n]);\n\n/**\n * @var mixed Extended example with available methods\n */\n$curl = (new Curler)\n\n    -\u003emethod('post')            // Set http method, default is \"get\"\n    -\u003eurl('http://example.com') // Set target url or path, same as -\u003eexec(URL)\n\n    /**\n     * Misc */\n    -\u003edisableDefaultUrl()       // If default_url is setted, disable for this instance\n    -\u003eresponseOnly()            // Returns CURL response content only\n    -\u003erequestInfo()             // getallheaders(), $_SERVER\n    -\u003ecurlInfo()                // curl_getinfo()\n\n\n    /**\n     * Set CURL Options */\n    -\u003esetOpt(CURLOPT_ENCODING, 'zip')\n    -\u003esetOpt(CURLOPT_USERAGENT, 'Many/Curler')\n    -\u003esetOpt(CURLOPT_AUTOREFERER, false)\n\n    // array alternate\n    -\u003esetOptArray([\n        CURLOPT_ENCODING =\u003e 'zip',\n        CURLOPT_USERAGENT =\u003e 'Many/Curler',\n        CURLOPT_AUTOREFERER =\u003e false,\n    ])\n\n\n    /**\n     * Header */\n    -\u003eheader([\n        'Authentication' =\u003e 'Many pw.2345',      // 'Authentication: Many pw.2345'\n        'Authentication' =\u003e ['Many', 'pw.2345'], // 'Authentication: Many pw.2345'\n    ])\n\n\n    /**\n     * HTTP Auth */\n    -\u003ehttpAuth(CURLAUTH_BASIC) // protection type\n    -\u003euserPwd('user', 'pass')  // or ('user:pass')\n\n    // CURLAUTH_ANY (.htaccess, uses basic or digest)\n    -\u003eauthAny('user', 'pass')\n\n    // CURLAUTH_BASIC\n    -\u003eauthBasic('user', 'pass')\n\n    // CURLAUTH_DIGEST\n    -\u003eauthDigest('user', 'pass')\n\n    // CURLAUTH_BEARER (?user optional, not .htaccess)\n    -\u003eauthBearer('token.lr.72.m', '?user')\n\n\n    /**\n     * Sets CURLOPT_CUSTOMREQUEST=POST and CURLOPT_POST=true internally.\n     * Arrays will be converted to strings using http_build_query() */\n    -\u003epost([\n        'lorem_ipsum' =\u003e 'dolor sit amet',\n    ])\n\n    /**\n     * Set postfields avoiding internally setted stuff to send data as body\n     * content, eg PUT. This class uses http_build_query(), if an array is\n     * given. Convert to any string format that fits your needs */\n    -\u003epostFields(\n        json_encode([\n            'lorem_ipsum' =\u003e 'dolor sit amet',\n        ])\n    )\n\n\n    /**\n     * Callback, run multiple callbacks through chaining in the given order.\n     * Each callback will use the resulting content from the previous one. */\n    -\u003ecallback('json_decode', true)             // any PHP internal function\n    -\u003ecallback('curlCallback')                  // custom function\n\n    // Custom class\n    -\u003ecallback('CallbackClass::run')            // (static) class::run()\n    -\u003ecallback('CallbackClass::class', 'init')  // (new class)-\u003einit() # init() could be any method\n    -\u003ecallback(CallbackClass::class, 'init')    // (new class)-\u003einit()\n\n    // Closure\n    -\u003ecallback(function($response) {\n        // Do stuff with $response here and\n        return $response;\n    })\n\n    // Pre validated callbacks, set simple validator functions to pre-validate the content.\n    // If Exceptions are enabled, throws Exceptions on fail, otherwise function gets ignored\n    -\u003ecallbackIf(['\\Many\\Http\\Curler::isJson'], 'json_decode', true)\n    -\u003ecallbackIf(['\\Many\\Http\\Curler::isJsonObj'], 'json_encode')\n    -\u003ecallbackIf(['is_string'], 'json_decode')\n\n    // Shorthands\n    -\u003ejsonDecode(true)                          // Shorty for json_decode()\n    -\u003ejsonEncode(JSON_PRETTY_PRINT)             // Shorty for json_encode()\n    -\u003ehtmlChars()                               // Shorty for htmlspecialchars()\n    -\u003ehtmlSpecialChars()                        // Shorty for -\u003ehtmlChars()\n\n\n    /**\n     * Final execs, getter */\n    -\u003eexec() // OR\n    -\u003eexec('/api/endpoint', [\n        CURLOPT_USERAGENT =\u003e 'AwesomeCurler', // set any CURL option here\n    ])\n\n    /**\n     * Alternate exec aliases. They all sets their name as REQUEST_METHOD\n     * internally. You can use -\u003epostFields(json_encode([])) to send content\n     * additionally in the body. */\n    -\u003edelete() // OR\n    -\u003edelete('/api/endpoint', [/* ... */])\n\n    -\u003eget()\n    -\u003eget('/api/endpoint', [/* ... */])\n\n    -\u003epatch()\n    -\u003epatch('/api/endpoint', [/* ... */])\n\n    -\u003eput()\n    -\u003eput('/api/endpoint', [/* ... */])\n```\n\n\n### Loading images\n\nTo convert images automatically to their valid string representations, set expected image types in `setConfig` (no defaults defined)\n\n```php\nCurler::setConfig([\n    'image_to_data' =\u003e [\n        'image/jpeg',\n        // 'image/png',\n        // 'image/webp',\n        // 'image/gif',\n        // 'image/x-icon',\n        // 'image/svg+xml',\n        // ...\n    ]\n]);\n\n$img = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aurora_and_sunset.jpg/200px-Aurora_and_sunset.jpg';\n\nif ($src = (new Curler)-\u003eresponseOnly()-\u003eget($img))\n    printf('\u003cimg src=\"%s\" alt=\"%s\" /\u003e', $src, $img);\n```\n\n\n#### Exceptions\n\nCatch AppCallbackException. The Class sends also additional http_header, if any errors occures.\n\n```php\nuse Many\\Exception\\AppCallbackException;\n\nCurler::setConfig([\n    'exceptions' =\u003e true,\n]);\n\ntry {\n    $get = (new Curler)\n        -\u003ecallback('theImpossibleFunction')\n        -\u003eget('/app/endpoint');\n} catch(AppCallbackException $e) {\n    $failed = $e-\u003egetMessage();\n}\n```\n\n\n#### Track requested URLs\n\nTo track CURL requests, set `curl_trace` to true, before doing any request.\n\n```php\nCurler::setConfig([\n    'curl_trace' =\u003e true,\n]);\n\n/** @var array Get all CURL requests with timestamps in an array */\n$curlGetTrace = Curler::getCurlTrace();\n```\n\n\n#### Misc methods\n\n```php\n/** @var int Get total amount of requests done so far */\n$curlsTotal = Curler::getCurlCount();\n\n/** @var array Get Config */\n$curlGetConfig = Curler::getConfig();\n\n/** @var array Get curl_setopt(), (true) all available CURL constants */\n$curlGetOptions = Curler::getOptions(true);\n\n/** @var mixed Get body content, (true) parsed to array */\n$curlGetBodyContent = Curler::getBodyContent(true);\n\n/** @var bool Check if val is JSON format */\n$isJson = Curler::isJson('{}', true); // (true) strict mode\n\n/** @var bool Check if val is valid JSON Object (is_array or is_object) */\n$isJsonObj = Curler::isJsonObj([]);\n\n/** @var string Readable Bytes */\n$memUsage = Curler::readableBytes(memory_get_usage());\n\n/** @var string Datetime with microseconds (microtime(true), $_SERVER['REQUEST_TIME_FLOAT']) */\n$microDate = Curler::dateMicroSeconds(null, 'Y-m-d H:i:s.u');\n\n/** @var string Get difference between two Dates with microseconds */\n$microDateDiff = Curler::dateMicroDiff(\n    Curler::dateMicroSeconds($_SERVER['REQUEST_TIME_FLOAT']), // script started (microtime(true))\n    Curler::dateMicroSeconds(),                               // current microtime(true)\n    '%s.%f'\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feypsilon%2Fcurler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feypsilon%2Fcurler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feypsilon%2Fcurler/lists"}