sargilla / curl by sargilla

PHP Curl library for the Laravel 5
12
0
3
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-04-18 15:02:34
Package Statistics
Total Downloads: 12
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

Sargilla/Curl

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)

  • Email: sargilla@gmail.com