{"id":26085265,"url":"https://github.com/codezero-be/curl","last_synced_at":"2025-03-09T05:58:04.613Z","repository":{"id":19966375,"uuid":"23233333","full_name":"codezero-be/curl","owner":"codezero-be","description":"Simple cURL wrapper","archived":false,"fork":false,"pushed_at":"2015-02-19T19:54:17.000Z","size":216,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-19T14:05:00.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/codezero-be.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-22T17:20:04.000Z","updated_at":"2015-02-19T19:54:12.000Z","dependencies_parsed_at":"2022-08-27T03:51:56.113Z","dependency_job_id":null,"html_url":"https://github.com/codezero-be/curl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fcurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fcurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fcurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fcurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codezero-be","download_url":"https://codeload.github.com/codezero-be/curl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242650948,"owners_count":20163611,"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":[],"created_at":"2025-03-09T05:58:03.317Z","updated_at":"2025-03-09T05:58:04.606Z","avatar_url":"https://github.com/codezero-be.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple cURL Wrapper\n\n[![GitHub release](https://img.shields.io/github/release/codezero-be/curl.svg)]()\n[![License](https://img.shields.io/packagist/l/codezero/curl.svg)]()\n[![Build Status](https://img.shields.io/travis/codezero-be/curl.svg?branch=master)](https://travis-ci.org/codezero-be/curl)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/codezero-be/curl.svg)](https://scrutinizer-ci.com/g/codezero-be/curl)\n[![Total Downloads](https://img.shields.io/packagist/dt/codezero/curl.svg)](https://packagist.org/packages/codezero/curl)\n\nThis package wraps most of the cURL functions in a dedicated `Curl` class, making it feel more object oriented and a little easier to use.\n\nMore importantly, the `Request` class provides some friendly methods that will set the most commonly used cURL options for you, so you don't have to memorize these.\n\nThis is a **simple** cURL wrapper. Some features are not supported (yet):\n\n- Including headers in the response output (`CURLOPT_HEADER`)\n- cURL multi handles\n- cURL share handles\n\n## Installation\n\nYou can download this package, or install it through Composer:\n\n    \"require\": {\n    \t\"codezero/curl\": \"1.*\"\n    }\n\n## Usage\n\nSend requests, the easy way!\n\n### Create a `Request` instance:\n\n    $request = new \\CodeZero\\Curl\\Request();\n\nYou can now use this for all of your requests. You don't need to create a new instance for every request.\n\n### Configure the request:\n    \n    $url = 'http://my.site/api';\n    $data = ['do' =\u003e 'something', 'with' =\u003e 'this']; //=\u003e Optional\n    $headers = ['Some Header' =\u003e 'Some Value']; //=\u003e Optional\n    \nIf you want you can set custom cURL options, before sending the request:\n\n    $request-\u003esetOption(CURLOPT_USERAGENT, 'My User Agent');\n    \n... or unset one:\n\n    $request-\u003eunsetOption(CURLOPT_USERAGENT);\n\n\u003e **NOTE:** Only the URL, data and headers option, and a few options that are required for the given request method will be reset automatically on every request. Custom options will remain set until you unset them. An overview of all cURL options can be found here: [http://php.net/manual/en/function.curl-setopt.php](http://php.net/manual/en/function.curl-setopt.php \"cURL options\")\n\n### Send the request: (one of the following)\n    \n    $response = $request-\u003eget($url, $data, $headers);\n    $response = $request-\u003epost($url, $data, $headers);\n    $response = $request-\u003eput($url, $data, $headers);\n    $response = $request-\u003epatch($url, $data, $headers);\n    $response = $request-\u003edelete($url, $data, $headers);\n\nAll of these methods will return an instance of the `CodeZero\\Curl\\Response` class.\n\n### Get the response body \n\n\t$body = $response-\u003egetBody();\n\n### Get additional request info\n\nFetch an array with all info:\n\n\t$info = $response-\u003einfo()-\u003egetList();\n\nFetch specific information:\n\n\t$httpCode = $response-\u003einfo()-\u003egetHttpCode(); //=\u003e \"200\"\n\t$responseType = $response-\u003einfo()-\u003egetResponseType(); //=\u003e \"application/json\"\n\t$responseCharset = $response-\u003einfo()-\u003egetResponseCharset(); //=\u003e \"UTF-8\" \n\n\u003e **TIP:** For an overview of all the available info, take a look at the `CodeZero\\Curl\\ResponseInfo` class or refer to [http://php.net/manual/en/function.curl-getinfo.php](http://php.net/manual/en/function.curl-getinfo.php \"cURL info\")\n \n## Exceptions\n\n#### cURL issues\n\nA `CodeZero\\Curl\\CurlException` will be thrown, if there was a problem initializing cURL. This will probably be the case if the cURL extension is not loaded by PHP, or if there is some other local server issue.\n\n#### Request issues\n\nA `CodeZero\\Curl\\RequestException` will be thrown, if cURL was unable to execute the request. This might be the case if your request is not properly configured (unsupported protocol, etc.). Find more information about these kind of errors on [http://curl.haxx.se/libcurl/c/libcurl-errors.html](http://curl.haxx.se/libcurl/c/libcurl-errors.html \"cURL errors\") \n\n#### Response issues\n\nHTTP response errors \u003e= 400 will not throw an exception, unless you set the `CURLOPT_FAILONERROR` cURL option to `true`. If you do, these errors will also throw a `CodeZero\\Curl\\RequestException`, with the proper error message.\n\nAnother way to handle HTTP errors is to check the `$httpCode` value:\n\n\tif ($httpCode \u003e= 400)\n\t{\n\t\t// Handle error...\n\t\t// or throw your own exception...\n\t}\n\n## Curl Class\n\nYou can also use the `Curl` class instead of the `Request` class. The difference is that you will need to provide all of the cURL options yourself and you will just get the raw response back instead of the `Response` object.\n\n### Quick example:\n\n    $options = [\n        CURLOPT_URL =\u003e 'http://my.site/api',\n        CURLOPT_SSL_VERIFYPEER =\u003e false,\n        CURLOPT_CUSTOMREQUEST =\u003e 'GET',\n        CURLOPT_HTTPGET =\u003e true,\n        CURLOPT_RETURNTRANSFER =\u003e true\n    ];\n\n    $curl = new \\CodeZero\\Curl\\Curl();\n\n\t// Send \u0026 get results\n    $responseBody = $curl-\u003esendRequest($options); //=\u003e Returns the actual output\n\t$info = $curl-\u003egetRequestInfo(); //=\u003e Returns info array\n\n\t// Get errors\n\t$error = $curl-\u003egetError(); //=\u003e For PHP \u003c 5.5.0 this is the same as $curl-\u003egetErrorDescription()\n\t$errorCode = $curl-\u003egetErrorCode();\n\t$errorDescription = $curl-\u003egetErrorDescription();\n\n\t// Close cURL resource\n\t$curl-\u003eclose();\n\nOptions are **not reset** automatically after each request. If you need to reset them, you can either run `$curl-\u003eclose()` to force a new cURL resource to be initialized at the next request, or you can call `$curl-\u003ereset()`.\n\n### Long example:\n\nThe following will do the exact same thing as the previous example:\n\n    $options = [\n        CURLOPT_URL =\u003e 'http://my.site/api',\n        CURLOPT_SSL_VERIFYPEER =\u003e false,\n        CURLOPT_CUSTOMREQUEST =\u003e 'GET',\n        CURLOPT_HTTPGET =\u003e true,\n        CURLOPT_RETURNTRANSFER =\u003e true\n    ];\n\n    $curl = new \\CodeZero\\Curl\\Curl();\n\n\t// Setup \u0026 send\n\t$curl-\u003einitialize();\n\t$curl-\u003esetOptions($options);\n    $curl-\u003esendRequest();\n\n\t// Get results\n\t$responseBody = $curl-\u003egetResponse(); //=\u003e Returns the actual output\n\t$info = $curl-\u003egetRequestInfo(); //=\u003e Returns info array\n\n\t// Get errors\n\t$error = $curl-\u003egetError();//=\u003e For PHP \u003c 5.5.0 this is the same as $curl-\u003egetErrorDescription()\n\t$errorCode = $curl-\u003egetErrorCode();\n\t$errorDescription = $curl-\u003egetErrorDescription();\n\n\t// Close cURL resource\n\t$curl-\u003eclose();\n\n### Error handling:\n\nThe `Curl` class will only throw a `CodeZero\\Curl\\CurlException`, when there is some cURL initialization issue. You will need to check the error code to determine if the request had any problems:\n\n\tif ($errorCode \u003e 0)\n\t{\n\t\t// Do something...\n\t}\n\n## Testing\n\n    $ vendor/bin/phpspec run\n\n## Security\n\nIf you discover any security related issues, please email \u003civan@codezero.be\u003e instead of using the issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n---\n[![Analytics](https://ga-beacon.appspot.com/UA-58876018-1/codezero-be/curl)](https://github.com/igrigorik/ga-beacon)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Fcurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodezero-be%2Fcurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Fcurl/lists"}