SimpleCurl for Laravel 4
A very simple and minimalistic cURL wrapper for Laravel 4., (*1)
Why?
There are a lot of great php HTTP clients out there in the wild. But sometimes you don't want/need the overhead of a full-featured client which forces you to write 15 lines of code to load a RSS feed or retrive data from an REST API., (*2)
$response = Curl::get('http://example.com/data.json');
SimpleCurl is the easy one-liner for this purpose. It's not intended to become the next guzzle, nor will it replace the Zend Http Client. ;), (*3)
Install
Composer:, (*4)
Add passioncoder/simplecurl
to the require
section of your composer.json
:, (*5)
"require": {
"passioncoder/simplecurl": "dev-master"
}
Laravel:, (*6)
Add the service provider to your app/config/app.php
:, (*7)
'providers' => array(
'Passioncoder\SimpleCurl\ServiceProvider',
),
Add the alias to your app/config/app.php
(optional):, (*8)
'aliases' => array(
'Curl' => 'Passioncoder\SimpleCurl\Facade',
),
Usage
Synopsis:, (*9)
$response = Curl::get($url, [array $params, [array $options]]);
$response = Curl::post($url, [array $params, [array $options]]);
-
$url
: A valid url
-
$params
: The get/post parameters as key/value pairs
-
$options
: cURL options as as key/value pairs
Example:, (*10)
try {
$response = Curl::get('http://example.com/data.json', ['foo' => 'bar'], [CURLOPT_HEADER => false]);
} catch (Passioncoder\SimpleCurl\Exception $e) {
print $e->getMessage();
}
var_dump($response->header);
var_dump($response->body);
if ($response->header->http_code == 200) {
print 'yeah!';
}
License
This package is open-sourced software licensed under the MIT license., (*11)