{"id":20140257,"url":"https://github.com/10quality/php-curl","last_synced_at":"2026-05-15T05:10:25.211Z","repository":{"id":56937898,"uuid":"138339673","full_name":"10quality/php-curl","owner":"10quality","description":"Library (wrapper) that provides functionality for when doing requests using Curl. Perfect for when developing custom API connectivity or creating generic requests.","archived":false,"fork":false,"pushed_at":"2023-01-05T19:54:07.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"v1.0","last_synced_at":"2025-03-02T23:26:18.781Z","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/10quality.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}},"created_at":"2018-06-22T19:14:11.000Z","updated_at":"2023-01-05T19:54:10.000Z","dependencies_parsed_at":"2023-02-04T13:32:34.438Z","dependency_job_id":null,"html_url":"https://github.com/10quality/php-curl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/10quality/php-curl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fphp-curl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fphp-curl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fphp-curl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fphp-curl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10quality","download_url":"https://codeload.github.com/10quality/php-curl/tar.gz/refs/heads/v1.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10quality%2Fphp-curl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33054511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2024-11-13T21:49:55.023Z","updated_at":"2026-05-15T05:10:25.194Z","avatar_url":"https://github.com/10quality.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Curl Wrapper (PHP)\n\n[![Latest Stable Version](https://poser.pugx.org/10quality/php-curl/v/stable)](https://packagist.org/packages/10quality/php-curl)\n[![Total Downloads](https://poser.pugx.org/10quality/php-curl/downloads)](https://packagist.org/packages/10quality/php-curl)\n[![License](https://poser.pugx.org/10quality/php-curl/license)](https://packagist.org/packages/10quality/php-curl)\n\nLibrary (wrapper) that provides functionality for when doing requests using Curl. Perfect for when developing custom API connectivity or creating generic requests.\n\n## Install\n\n```bash\ncomposer require 10quality/php-curl\n```\n\n## Usage\n\n### Request call options\n\nYou can make your request call using the following options:\n```php\n// With global `curl_request()`\n$response = curl_request('http://my-api.com');\n\n// With global `get_curl_contents()`\n// --- Which is an alias of `curl_request()`\n$response = get_curl_contents('http://my-api.com');\n\n// With class `Curl`\n$response = Curl::request('http://my-api.com');\n```\n\n### Parameters\n\nParameters sample:\n```php\n$response = curl_request($url, $method, $data, $headers, $options);\n```\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| `$url` | `string` | Request URL. |\n| `$method` | `string` | Request method (`GET` by default). Available options: **GET**, **POST**, **JPOST**, **JPUT**, **JGET**, **JDELETE**, **JUPDATE**, **JPATCH**. Json request is sent in those with the *J* prefix. |\n| `$data` | `array` | The request data to send via query string, request body or both (Empty by default). |\n| `$headers` | `array` | The list of request headers to add (Empty by default). |\n| `$options` | `array` | The list of curl options to add (Empty by default). |\n| `$callable` | `mixed` | Callable for when an unknown method is requested (null by default). |\n\n#### Query string and post body\n\nGET sample:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'GET',\n    [\n        'action'    =\u003e 'get-countries',\n        'format'    =\u003e 'xml',\n    ]\n);\n```\n\nPOST sample:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'POST',\n    [\n        'action'    =\u003e 'get-countries',\n        'format'    =\u003e 'xml',\n        'search'    =\u003e 'united',\n        'limit'     =\u003e 5,\n    ]\n);\n```\n\nUsing both:\n\nDefine `$data` array keys *query_string* and *request_body* to send some parameters as query string or request body. In the following example `action` and `format` will send as query string and `search` and `limit` as post body:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'POST',\n    [\n        'query_string' =\u003e [\n            'action'    =\u003e 'get-countries',\n            'format'    =\u003e 'xml',\n        ],\n        'request_body' =\u003e [\n            'search'    =\u003e 'united',\n            'limit'     =\u003e 5,\n        ],\n    ]\n);\n```\n\nThe example below will generate the following request:\n```bash\nurl:        http://my-api.com?action=get-countries\u0026format=xml\npost body:  search=united\u0026limit=5\n```\n\n#### Headers\n\nThe following example shows how to send headers:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'GET',\n    ['action' =\u003e 'get-countries'],\n    [\n        'Authorization: Bearer -token-',\n        'Custom: Value',\n    ]\n);\n```\n\n#### Curl options\n\nThe following example shows how to add curl options or override existing:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'GET',\n    ['action' =\u003e 'get-countries'],\n    [],\n    [\n        CURLOPT_TIMEOUT         =\u003e 60,\n        CURLOPT_RETURNTRANSFER  =\u003e 0,\n        CURLOPT_USERAGENT       =\u003e 'Custom/Agent 007',\n    ]\n);\n```\n\n#### Custom request method using callables\n\nIf you need to make a special request to a different method from the ones supported, you can use the the `$callable` parameter as shown in the following sample:\n```php\n$response = curl_request(\n    'http://my-api.com',\n    'XPOST',\n    [],\n    ['temperature' =\u003e 60, 'uptime' =\u003e 4564612131],\n    [],// headers\n    [],// options\n    function($curl, $data) {\n        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'XPOST');\n        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));\n        return $curl;\n    }\n);\n```\n\n**NOTE:** The callable will receive `$curl` and `$data` as parameters and it is expecting to return the variable `$curl` back.\n\n## Guidelines\n\nPSR-2 coding standards.\n\n## Copyright and License\n\nMIT License - (C) 2018 [10 Quality](https://www.10quality.com/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10quality%2Fphp-curl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10quality%2Fphp-curl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10quality%2Fphp-curl/lists"}