sargilla/curl

PHP Curl library for the Laravel 5

dev-master 2016-05-30 18:07 UTC

This package is auto-updated.

Last update: 2024-11-25 19:11:18 UTC


README

Custom PHP cURL library for the Laravel 5 framework

Installation

Pull this package in through Composer.

    {
        "require": {
            "sargilla/curl": "dev-master"
        }
    }

Laravel 5.* Integration

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,

    ),

Integration without Laravel

Create a new instance of the CurlService where you would like to use the package:

    $curlService = new \Sargilla\Curl\CurlService();

Usage

Laravel usage

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.

Sending GET requests

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
    

Sending POST requests

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
    

Downloading files

For downloading a file, you can use the download() method:

    // Download an image from: file http://www.foo.com/bar.png
   

Usage without Laravel

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();

License

This template is open-sourced software licensed under the MIT license

Contact

Santiago Argilla (developer)