Package Data | |
---|---|
Maintainer Username: | sargilla |
Maintainer Contact: | sargilla@gmail.com (Santiago Argilla) |
Package Create Date: | 2016-04-17 |
Package Last Update: | 2016-05-30 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:04:23 |
Package Statistics | |
---|---|
Total Downloads: | 12 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Custom PHP cURL library for the Laravel 5 framework
Pull this package in through Composer.
{
"require": {
"sargilla/curl": "dev-master"
}
}
Add the service provider to your config/app.php
file:
'providers' => array(
//...
Sargilla\Curl\CurlServiceProvider::class,
),
Add the alias to your config/app.php
file:
'aliases' => array(
//...
'Curl' => Sargilla\Curl\Facades\Curl::class,
),
Create a new instance of the CurlService
where you would like to use the package:
$curlService = new \Sargilla\Curl\CurlService();
The package provides an easy interface for sending cURL requests from your application. The package provides a fluent interface similar the Laravel query builder to easily configure the request. There are several utility methods that allow you to easily add certain options to the request.
In order to send a GET
request, you need to use the get()
method that is provided by the package:
// Send a GET request to: http://www.foo.com/bar
// Send a GET request to: http://www.foo.com/bar?foz=baz
// Send a GET request to: http://www.foo.com/bar?foz=baz using JSON
Post requests work similar to GET
requests, but use the post()
method instead:
// Send a POST request to: http://www.foo.com/bar
// Send a POST request to: http://www.foo.com/bar
// Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON
// Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON and return as associative array
For downloading a file, you can use the download()
method:
// Download an image from: file http://www.foo.com/bar.png
Usage without Laravel is identical to usage described previously. The only difference is that you will not be able to
use the facades to access the CurlService
.
$curlService = new \Sargilla\Curl\CurlService();
// Send a GET request to: http://www.foo.com/bar
$response = $curlService->to('http://www.foo.com/bar')
->get();
// Send a POST request to: http://www.foo.com/bar
$response = $curlService->to('http://www.foo.com/bar')
->post();
This template is open-sourced software licensed under the MIT license
Santiago Argilla (developer)