{"id":14989941,"url":"https://github.com/ixudra/curl","last_synced_at":"2025-05-14T23:05:14.115Z","repository":{"id":15747513,"uuid":"18486198","full_name":"ixudra/curl","owner":"ixudra","description":"Custom PHP curl library for the Laravel 5 framework - developed by Ixudra","archived":false,"fork":false,"pushed_at":"2024-04-22T18:36:06.000Z","size":135,"stargazers_count":563,"open_issues_count":3,"forks_count":129,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-06T14:13:15.347Z","etag":null,"topics":["curl","ixudra","laravel","requests"],"latest_commit_sha":null,"homepage":"","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/ixudra.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2014-04-06T09:18:12.000Z","updated_at":"2025-04-26T10:49:15.000Z","dependencies_parsed_at":"2024-06-18T10:51:32.191Z","dependency_job_id":"a9df6900-a8bf-4f27-bf28-27ecfe020e62","html_url":"https://github.com/ixudra/curl","commit_stats":{"total_commits":109,"total_committers":30,"mean_commits":"3.6333333333333333","dds":0.3486238532110092,"last_synced_commit":"ac1844e9770995a493fd92b6b18b254b1636f2d0"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixudra%2Fcurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixudra%2Fcurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixudra%2Fcurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixudra%2Fcurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ixudra","download_url":"https://codeload.github.com/ixudra/curl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253445049,"owners_count":21909736,"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":["curl","ixudra","laravel","requests"],"created_at":"2024-09-24T14:19:11.919Z","updated_at":"2025-05-14T23:05:09.102Z","avatar_url":"https://github.com/ixudra.png","language":"PHP","funding_links":["https://www.patreon.com/ixudra)!!"],"categories":["Packages"],"sub_categories":["Helpers/General"],"readme":"ixudra/curl\n================\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/ixudra/curl.svg?style=flat-square)](https://packagist.org/packages/ixudra/curl)\n[![license](https://img.shields.io/github/license/ixudra/curl.svg)]()\n[![Total Downloads](https://img.shields.io/packagist/dt/ixudra/curl.svg?style=flat-square)](https://packagist.org/packages/ixudra/curl)\n\n\n![Ixudra Curl](https://repository-images.githubusercontent.com/18486198/cd2b2080-de01-11e9-8fb1-e64ffe5e9816)\n\nCustom PHP cURL library for the Laravel framework - developed by [Ixudra](http://ixudra.be).\n\nThe package provides an easy interface for sending cURL requests from your PHP web application. The package provides an \nintuitive, fluent interface similar the Laravel query builder to easily configure the request. Additionally, There are \nseveral utility methods that allow you to easily add certain options to the request. This makes it easier to create and\nuse cURL requests and also makes your code more comprehensible.\n\nThe provided functionality is completely framework-independent but also contains a Laravel service provider for easy \nintegration into your Laravel project.\n\n\n \u003e Note before posting an issue: When posting an issue for the package, always be sure to provide as much information \n \u003e regarding the request as possible. This includes the example cURL request you are trying to transfer into the package\n \u003e syntax, your actual package syntax (the full request) and (if possible) an example URL I can use to test the request\n \u003e myself if need be.\n\n\n\n\n## Installation\n\nPull this package in through Composer.\n\n```js\n\n    {\n        \"require\": {\n            \"ixudra/curl\": \"6.*\"\n        }\n    }\n\n```\n\nor run in terminal:\n`composer require ixudra/curl`\n\n### Laravel 5.5+ Integration\n\nLaravel's package discovery will take care of integration for you.\n\n\n### Laravel 5.* Integration\n\nAdd the service provider to your `config/app.php` file:\n\n```php\n\n    'providers'     =\u003e array(\n\n        //...\n        Ixudra\\Curl\\CurlServiceProvider::class,\n\n    ),\n\n```\n\nAdd the facade to your `config/app.php` file:\n\n```php\n\n    'aliases'       =\u003e array(\n\n        //...\n        'Curl'          =\u003e Ixudra\\Curl\\Facades\\Curl::class,\n\n    ),\n\n```\n\n\n### Laravel 4.* Integration\n\nAdd the service provider to your `app/config/app.php` file:\n\n```php\n\n    'providers'     =\u003e array(\n\n        //...\n        'Ixudra\\Curl\\CurlServiceProvider',\n\n    ),\n\n```\n\nAdd the facade to your `app/config/app.php` file:\n\n```php\n\n    'facades'       =\u003e array(\n\n        //...\n        'Curl'          =\u003e 'Ixudra\\Curl\\Facades\\Curl',\n\n    ),\n\n```\n\n\n### Lumen 5.* integration\n\nIn your `bootstrap/app.php`, make sure you've un-commented the following line (around line 26):\n\n```\n$app-\u003ewithFacades();\n```\n\nThen, register your class alias:\n```\nclass_alias('Ixudra\\Curl\\Facades\\Curl', 'Curl');\n```\n\nFinally, you have to register your ServiceProvider (around line 70-80):\n\n```\n/*\n|--------------------------------------------------------------------------\n| Register Service Providers\n|--------------------------------------------------------------------------\n|\n| Here we will register all of the application's service providers which\n| are used to bind services into the container. Service providers are\n| totally optional, so you are not required to uncomment this line.\n|\n*/\n\n// $app-\u003eregister('App\\Providers\\AppServiceProvider');\n\n// Package service providers\n$app-\u003eregister(Ixudra\\Curl\\CurlServiceProvider::class);\n```\n\n\n### Integration without Laravel\n\nCreate a new instance of the `CurlService` where you would like to use the package:\n\n```php\n\n    $curlService = new \\Ixudra\\Curl\\CurlService();\n\n```\n\n\n\n\n## Usage\n\n### Laravel usage\n\nThe package provides an easy interface for sending cURL requests from your application. The package provides a fluent\ninterface similar the Laravel query builder to easily configure the request. There are several utility methods that allow\nyou to easily add certain options to the request. If no utility method applies, you can also use the general `withOption`\nmethod.\n\n### Sending GET requests\n\nIn order to send a `GET` request, you need to use the `get()` method that is provided by the package:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003eget();\n\n    // Send a GET request to: http://www.foo.com/bar?foz=baz\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003eget();\n\n    // Send a GET request to: http://www.foo.com/bar?foz=baz using JSON\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003easJson()\n        -\u003eget();\n\n```\n\n\n### Sending POST requests\n\nPost requests work similar to `GET` requests, but use the `post()` method instead:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a POST request to: http://www.foo.com/bar\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003epost();\n    \n    // Send a POST request to: http://www.foo.com/bar\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003epost();\n    \n    // Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003easJson()\n        -\u003epost();\n    \n    // Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON and return as associative array\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003easJson( true )\n        -\u003epost();\n\n```\n\n\n### Sending PUT requests\n\nPut requests work similar to `POST` requests, but use the `put()` method instead:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a PUT request to: http://www.foo.com/bar/1 with arguments 'foz' = 'baz' using JSON\n    $response = Curl::to('http://www.foo.com/bar/1')\n       -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n       -\u003easJson()\n       -\u003eput();\n\n```\n\n\n### Sending PATCH requests\n\nPatch requests work similar to `POST` requests, but use the `patch()` method instead:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a PATCH request to: http://www.foo.com/bar/1 with arguments 'foz' = 'baz' using JSON\n    $response = Curl::to('http://www.foo.com/bar/1')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003easJson()\n        -\u003epatch();\n\n```\n\n\n### Sending DELETE requests\n\nDelete requests work similar to `GET` requests, but use the `delete()` method instead:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a DELETE request to: http://www.foo.com/bar/1 using JSON\n    $response = Curl::to('http://www.foo.com/bar/1')\n        -\u003easJson()\n        -\u003edelete();\n\n```\n\n\n### Sending HEAD requests\n\nHEAD requests work similar to `GET` requests, but use the `head()` method instead:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a HEAD request to: http://www.foo.com/bar/1\n    $response = Curl::to('http://www.foo.com/bar/1')\n        -\u003ehead();\n    \n    // Send a HEAD request to: http://www.foo.com/bar/1?foz=baz\n    $response = Curl::to('http://www.foo.com/bar/1')\n        -\u003ewithData( array( 'foz' =\u003e 'baz' ) )\n        -\u003ehead();\n\n```\n\n\n### Sending custom headers\n\nSending custom headers is easy with the `withHeader()` method. Multiple calls can be chained together to add multiple headers to the request:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with 2 custom headers\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithHeader('MyFirstHeader: 123')\n        -\u003ewithHeader('MySecondHeader: 456')\n        -\u003eget();\n\n```\n\nAlternatively, you can use the `withHeaders()` to combine multiple headers into one method call:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with 2 custom headers\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithHeaders( array( 'MyFirstHeader: 123', 'MySecondHeader: 456' ) )\n        -\u003eget();\n\n```\n\nYou can also use key-value when using the `withHeaders()` method:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with 2 custom headers\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithHeaders( array( 'MyFirstHeader' =\u003e '123', 'MySecondHeader' =\u003e '456' ) )\n        -\u003eget();\n\n```\n\nFor (bearer) authorization headers, you can also use specific utility methods:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with \"Authorization: 123\" header\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithAuthorization('123')\n        -\u003eget();\n\n    // Send a GET request to: http://www.foo.com/bar with \"Authorization: Bearer 123\" header\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithBearer('123')\n        -\u003eget();\n\n```\n\n \u003e Note that headers will override each other if you add the same header more than once.\n\n\n### Specifying the content type\n\nSending custom headers is easy with the `withContentType()` method. Multiple calls can be chained together to add multiple headers to the request:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with a json content type\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithContentType('application/json')\n        -\u003eget();\n\n```\n\n\n### Using proxies\n\nIf you need to send your requests via a proxy, you can use the 'withProxy()' method. The method takes five parameters:\n\n- proxy url (required)\n- port (optional)\n- type of proxy scheme (optional, e.g. `http://`, `https://`, ...)\n- username (optional)\n- password (optional)\n\nOptional parameters will be ignored if not filled in.\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to: http://www.foo.com/bar with a json content type\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithProxy('192.168.1.1', 80, 'http://', 'Foo', 'Bar')\n        -\u003eget();\n\n```\n\n\n### Sending files via Curl\n\nFor sending files via a POST request, you can use the `withFile` method to correctly format a request before sending:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    $response = Curl::to('http://foo.com/bar')\n        -\u003ewithData( array( 'Foo' =\u003e 'Bar' ) )\n        -\u003ewithFile( 'image_1', '/path/to/dir/image1.png', 'image/png', 'imageName1.png' )\n        -\u003ewithFile( 'image_2', '/path/to/dir/image2.png', 'image/png', 'imageName2.png' )\n        -\u003epost();\n\n```\n\nYou can add as many files to the request as you want. A couple of things to keep in mind:\n\n- When submitting files, the `asJson()` method and `asJsonRequest()` method cannot be used. If you do, the files will not be transferred correctly\n- The files are added to the data that was provided in the `withData()` method using the first parameter of the `withFile()` method. If this key already exists, it will be overridden.\n\n\n### Downloading files\n\nFor downloading a file, you can use the `download()` method:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Download an image from: file http://www.foo.com/bar.png\n    $response = Curl::to('http://foo.com/bar.png')\n        -\u003ewithContentType('image/png')\n        -\u003edownload('/path/to/dir/image.png');\n\n```\n\n\n### Using response objects\n\nBy default, the package will only return the content of the request. In some cases, it might also be useful to know\nadditional request information, such as the HTTP status code and error messages should they occur. In this case, you\ncan use the `returnResponseObject()` method, which will return an stdClass that contains additional information as \nwell as the response content:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to http://www.foo.com/bar and return a response object with additional information\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ereturnResponseObject()\n        -\u003eget();\n            \n    $content = $response-\u003econtent;\n\n```\n\nThe response object will look like this:\n\n```json\n{\n   \"content\": \"Message content here\",\n   \"status\": 200,\n   \"contentType\": \"content-type response header (ex: application/json)\",\n   \"error\": \"Error message goes here (Only added if an error occurs)\"\n}\n```\n\n### Response headers\n\nIn some cases it might be relevant to return the response headers back to the user. This can easily be done using the `withResponseHeaders()` method.\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to http://www.foo.com/bar and return a response object with additional information including response headers\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003ewithResponseHeaders()\n        -\u003ereturnResponseObject()\n        -\u003eget();\n            \n    $content = $response-\u003econtent;\n    $headers = $response-\u003eheaders;\n\n```\n\nThe response object will look like this:\n\n```json\n{\n    \"content\": \"Message content here\",\n    \"status\": 200,\n    \"contentType\": \"content-type response header (ex: application/json)\",\n    \"error\": \"Error message goes here (Only added if an error occurs)\",\n    \"headers\": {\n        \"header-type-1\": \"header-content-1\",\n        \"header-type-2\": \"header-content-2\"\n    }\n}\n```\n\nIt is important to note that the `withResponseHeaders()` method must be used in conjunction with the `returnResponseObject()` method in order to see the returned headers\n\n\n### Debugging requests\n\nIn case a request fails, it might be useful to get debug the request. In this case, you can use the `enableDebug()` method.\nThis method uses one parameter, which is the name of the file in which the debug information is to be stored:\n\n```php\n\n    use Ixudra\\Curl\\Facades\\Curl;\n\n    // Send a GET request to http://www.foo.com/bar and log debug information in /path/to/dir/logFile.txt\n    $response = Curl::to('http://www.foo.com/bar')\n        -\u003eenableDebug('/path/to/dir/logFile.txt')\n        -\u003eget();\n\n```\n\n\n### Using cURL options\n\nYou can add various cURL options to the request using of several utility methods such as `withHeader()` for adding a\nheader to the request, or use the general `withOption()` method if no utility method applies. The package will\nautomatically prepend the options with the `CURLOPT_` prefix. It is worth noting that the package does not perform\nany validation on the cURL options. Additional information about available cURL options can be found\n[here](http://php.net/manual/en/function.curl-setopt.php).\n\n| Method                |  Default value    | Description                                                       |\n|-----------------------|-------------------|-------------------------------------------------------------------|\n| withTimeout()         |  30 seconds       | Set the timeout of the request (integer or float)                 |\n| withConnectTimeout()  |  30 seconds       | Set the connect timeout of the request (integer or float)         |\n| allowRedirect()       |  false            | Allow the request to be redirected internally                     |\n| asJsonRequest()       |  false            | Submit the request data as JSON                                   |\n| asJsonResponse()      |  false            | Decode the response data from JSON                                |\n| asJson()              |  false            | Utility method to set both `asJsonRequest()` and `asJsonResponse()` at the same time   |\n| withHeader()          |  string           | Add an HTTP header to the request                                 |\n| withHeaders()         |  array            | Add multiple HTTP headers to the request                          |\n| withContentType()     |  none             | Set the content type of the response                              |\n| withFile()            |  none             | Add a file to the form data to be sent                            |\n| containsFile()        |  false            | Should be used to submit files through forms                      |\n| withData()            |  array            | Add an array of data to sent with the request (GET or POST)       |\n| setCookieFile()       |  none             | Set a file to read cookies from                                   |\n| setCookieJar()        |  none             | Set a file to store cookies in                                    |\n| withOption()          |  none             | Generic method to add any cURL option to the request              |\n\nFor specific information regarding parameters and return types, I encourage you to take a look at \n`ixudra\\curl\\src\\Ixudra\\Curl\\Builder.php`. This class has extensive doc blocks that contain all the necessary information\nfor each specific method.\n\n\n\n### Usage without Laravel\n\nUsage without Laravel is identical to usage described previously. The only difference is that you will not be able to\nuse the facades to access the `CurlService`.\n\n```php\n\n    $curlService = new \\Ixudra\\Curl\\CurlService();\n\n    // Send a GET request to: http://www.foo.com/bar\n    $response = $curlService-\u003eto('http://www.foo.com/bar')\n        -\u003eget();\n\n    // Send a POST request to: http://www.foo.com/bar\n    $response = $curlService-\u003eto('http://www.foo.com/bar')\n        -\u003epost();\n\n    // Send a PUT request to: http://www.foo.com/bar\n    $response = $curlService-\u003eto('http://www.foo.com/bar')\n        -\u003eput();\n\n    // Send a DELETE request to: http://www.foo.com/bar\n    $response = $curlService-\u003eto('http://www.foo.com/bar')\n        -\u003edelete();\n\n    // Send a HEAD request to: http://www.foo.com/bar\n    $response = $curlService-\u003eto('http://www.foo.com/bar')\n        -\u003ehead();\n\n```\n\n\n\n\n## Planning\n\n - Add additional utility methods for other cURL options\n - Add contract to allow different HTTP providers such as Guzzle\n\n\n\n\n## Support\n\nHelp me further develop and maintain this package by supporting me via [Patreon](https://www.patreon.com/ixudra)!!\n\n\n\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)\n\n\n\n\n## Contact\n\nFor package questions, bug, suggestions and/or feature requests, please use the Github issue system and/or submit a pull request. When submitting an issue, always provide a detailed explanation of your problem, any response or feedback your get, log messages that might be relevant as well as a source code example that demonstrates the problem. If not, I will most likely not be able to help you with your problem. Please review the [contribution guidelines](https://github.com/ixudra/curl/blob/master/CONTRIBUTING.md) before submitting your issue or pull request.\n\nFor any other questions, feel free to use the credentials listed below: \n\nJan Oris (developer)\n\n- Email: jan.oris@ixudra.be\n- Telephone: +32 496 94 20 57\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixudra%2Fcurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fixudra%2Fcurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixudra%2Fcurl/lists"}