Recommend this page to a friend! |
![]() |
Info | Documentation | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 231 | All time: 8,152 This week: 35![]() |
Version | License | PHP version | Categories | |||
curler 1.0 | Custom (specified... | 7.1 | HTTP, PHP 5 |
Description | Author | |
This package can send HTTP requests and return responses using CURL. |
|
Very Fast Curl class
The fastest Curl class
An elegant PHP HTTP client for sending HTTP requests.
This library can easily be installed using composer. Run the command below:
composer require coderatio/curler
___
GET
Because this is built with simplicity in mind from the beginning, below is how easy you can make a get request to another server.
require 'vendor/autoload.php';
$curler = new \Coderatio\Curler\Curler();
$curler->get('https://jsonplaceholder.typicode.com/todos');
$response = $curler->getResponse();
POST
$data = [
'title' => 'Sample post',
'body' => 'This is a sample post',
'userId' => 1
];
$curler = new \Coderatio\Curler\Curler();
$request = $curler->post('https://jsonplaceholder.typicode.com/posts', $data);
$response = $curler->getResponse();
POST FORM
Sending form data via curler is as simple sending a post
request. Just send an array of your form data and curler will take care of the rest. Take a look below:
$data = [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com'
];
$curler = new \Coderatio\Curler\Curler();
$request = $curler->postForm('https://example.com/store-user', $data);
$response = $curler->getResponse();
By default, the $response
variable will hold a json object of the request. But, there are instances where you want the response in php object or array. You can get them as below:
$response = $curler->getResponse()->asObject();
OR
$response = $curler->getResponse()->asArray();
___
Just as you use the post, get, postForm e.t.c, you can also use the put
, delete
, download
, options
, head
, and trace
methods.
___
Sometimes, you may need to send your request with custom headers. Curler, has full support for that and many more. Here is how it can be done. * ### Single Header
$curler = new \Coderatio\Curler\Curler();
$curler->appendRequestHeader('Content-Type', 'application/json');
$curler->post('https://jsonplaceholder.typicode.com/posts', $data);
$response = $curler->getResponse();
### Multiple headers
$curler = new \Coderatio\Curler\Curler();
$curler->appendRequestHeaders([
'Content-Type' => 'application/xml',
'x-access-token' => 'xxxxxxxxxx'
]);
$curler->post('https://jsonplaceholder.typicode.com/posts', $data);
$response = $curler->getResponse();
___
## Get Status Code
Sometimes, you may like to get the status code returned from a request. This can easily be done with curler as below:
$curler->statuseCode;
___
## Add cURL options
Since this package is built with flexibility in mind, adding cURL options should be a breeze. Here is how you can add options:
$curler->addCurlOption('CURLOPT_PUT', true); // Single
// OR
$curler->addCurlOptions([
'CURLOPT_PUT' => true,
'CURLOPT_POSTFIELDS' => []
]);
## Contributors
To be a contributor, kindly fork the repo, add or fix bugs and send a pull request.
## Contribution
To contribute to this project, kindly fork it and send a pull request or find me on <a href="https://twitter.com/josiahoyahaya">Twitter</a>.
## License
This project is licenced with the MIT license.
Files (7)
File
Role
Description
src (1 file, 2 directories)
composer.json
Data
Auxiliary data
LICENSE
Lic.
License text
README.md
Doc.
Documentation
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer
Version Control Unique User Downloads Download Rankings 100% Total: 231 This week: 0
All time: 8,152 This week: 35 
Applications that use this package
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.