This is a PHP wrapper for cURL
This project was created to help developers easily interact with the underlying cURL API.
These instructions will get you a copy of Easy Curl up and running.
In order to install this package you have to install composer
which can be done by following the steps based on your system here.
If you have not done so already run composer init
in the root of your project directory, do so now to start using composer. Just follow the prompts as they appear.
To install Easy Curl run the command below while in your project root.
composer require lowem/easy-curl
Create a new PHP file and add the code below to the top of the file to automatically load in the package as well as any others you may have installed. The use
statement prevents you from having to type in the full namespace of the package.
require_once "vendor/autoload.php";
use Lowem\EasyCurl\EasyCurl;
header
: This is an array of HTTP header fields- Example:
[ "Content-Type: application/json", "Accept: application/json" ]
$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts"); try { $test->get(); } catch (HTTPRequestException $e) { echo $e->getCustomMessage(); } print_r($test->getExecMessage()); $test->close();
- Example:
postFields
: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.- Example:
[ "title" => "foo", "body" => "bar", "userId" => 1 ]
- Example:
header
: This is an array of HTTP header fields- Example:
[ "Content-Type: application/json", "Accept: application/json" ]
$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts"); try { $data = [ "title" => "foo", "body" => "bar", "userId" => 1 ]; $test->post(json_encode($data), [ "Content-type: application/json; charset=UTF-8", ]); } catch (HTTPRequestException $e) { echo $e->getCustomMessage(); } print_r($test->getExecMessage()); $test->close();
- Example:
postFields
: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.- Example:
[ "id" => 1, "title" => "foo", "body" => "bar", "userId" => 1 ]
- Example:
header
: This is an array of HTTP header fields- Example:
[ "Content-Type: application/json", "Accept: application/json" ]
$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1"); try { $data = [ "id" => 1, "title" => "foo", "body" => "bar", "userId" => 1 ]; $test->put(json_encode($data), [ "Content-type: application/json; charset=UTF-8", ]); } catch (HTTPRequestException $e) { echo $e->getCustomMessage(); } print_r($test->getExecMessage()); $test->close();
- Example:
$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
try {
$test->delete();
} catch (HTTPRequestException $e) {
echo $e->getCustomMessage();
}
print_r($test->getExecMessage());
$test->close();
- @Lowe-Man - Idea & Initial work
See also the list of contributors who participated in this project.