1. Go to this page and download the library: Download apitoolkits/curl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$curlService = new \Apitoolkits\Curl\CurlService();
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to: http://www.foo.com/bar
$response = Curl::to('http://www.foo.com/bar')
->get();
// Send a GET request to: http://www.foo.com/bar?foz=baz
$response = Curl::to('http://www.foo.com/bar')
->withData( array( 'foz' => 'baz' ) )
->get();
// Send a GET request to: http://www.foo.com/bar?foz=baz using JSON
$response = Curl::to('http://www.foo.com/bar')
->withData( array( 'foz' => 'baz' ) )
->asJson()
->get();
use Apitoolkits\Curl\Facades\Curl;
// Send a POST request to: http://www.foo.com/bar
$response = Curl::to('http://www.foo.com/bar')
->post();
// Send a POST request to: http://www.foo.com/bar
$response = Curl::to('http://www.foo.com/bar')
->withData( array( 'foz' => 'baz' ) )
->post();
// Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON
$response = Curl::to('http://www.foo.com/bar')
->withData( array( 'foz' => 'baz' ) )
->asJson()
->post();
// Send a POST request to: http://www.foo.com/bar with arguments 'foz' = 'baz' using JSON and return as associative array
$response = Curl::to('http://www.foo.com/bar')
->withData( array( 'foz' => 'baz' ) )
->asJson( true )
->post();
use Apitoolkits\Curl\Facades\Curl;
// Send a PUT request to: http://www.foo.com/bar/1 with arguments 'foz' = 'baz' using JSON
$response = Curl::to('http://www.foo.com/bar/1')
->withData( array( 'foz' => 'baz' ) )
->asJson()
->put();
use Apitoolkits\Curl\Facades\Curl;
// Send a PATCH request to: http://www.foo.com/bar/1 with arguments 'foz' = 'baz' using JSON
$response = Curl::to('http://www.foo.com/bar/1')
->withData( array( 'foz' => 'baz' ) )
->asJson()
->patch();
use Apitoolkits\Curl\Facades\Curl;
// Send a DELETE request to: http://www.foo.com/bar/1 using JSON
$response = Curl::to('http://www.foo.com/bar/1')
->asJson()
->delete();
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to: http://www.foo.com/bar with 2 custom headers
$response = Curl::to('http://foo.com/bar')
->withHeader('MyFirstHeader: 123')
->withHeader('MySecondHeader: 456')
->get();
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to: http://www.foo.com/bar with 2 custom headers
$response = Curl::to('http://foo.com/bar')
->withHeaders( array( 'MyFirstHeader: 123', 'MySecondHeader: 456' ) )
->get();
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to: http://www.foo.com/bar with a json content type
$response = Curl::to('http://foo.com/bar')
->withContentType('application/json')
->get();
use Apitoolkits\Curl\Facades\Curl;
// Download an image from: file http://www.foo.com/bar.png
$response = Curl::to('http://foo.com/bar.png')
->withContentType('image/png')
->download('/path/to/dir/image.png');
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to http://www.foo.com/bar and return a response object with additional information
$response = Curl::to('http://www.foo.com/bar')
->returnResponseObject()
->get();
$content = $response->content;
use Apitoolkits\Curl\Facades\Curl;
// Send a GET request to http://www.foo.com/bar and log debug information in /path/to/dir/logFile.txt
$response = Curl::to('http://www.foo.com/bar')
->enableDebug('/path/to/dir/logFile.txt')
->get();
$curlService = new \Apitoolkits\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();
// Send a PUT request to: http://www.foo.com/bar
$response = $curlService->to('http://www.foo.com/bar')
->put();
// Send a DELETE request to: http://www.foo.com/bar
$response = $curlService->to('http://www.foo.com/bar')
->delete();