A simple PHP package to send and receive HTTP requests using the cURL library.
To install this package, use Composer:
composer require allissonaraujo/sugardata:dev-main
Here's a basic example of how to use the SugarData class to send a POST request:
require 'vendor/autoload.php';
use Allissonaraujo\SugarData\SugarData;
$url = 'https://jsonplaceholder.typicode.com/posts';
$data = [
'title' => 'foo',
'body' => 'bar',
'userId' => 1
];
$request = new SugarData($url, $data);
$response = $request->send();
print_r($response);
require 'vendor/autoload.php';
use Allissonaraujo\SugarData\SugarData;
$url = 'https://jsonplaceholder.typicode.com/posts';
$data = [
'userId' => 1
];
$request = new SugarData($url, $data, 'GET');
$response = $request->send();
print_r($response);
require 'vendor/autoload.php';
use Allissonaraujo\SugarData\SugarData;
$url = 'https://jsonplaceholder.typicode.com/posts/1';
$data = [
'id' => 1,
'title' => 'foo',
'body' => 'bar',
'userId' => 1
];
$request = new SugarData($url, $data, 'PUT');
$response = $request->send();
print_r($response);
require 'vendor/autoload.php';
use Allissonaraujo\SugarData\SugarData;
$url = 'https://jsonplaceholder.typicode.com/posts/1';
$data = [];
$request = new SugarData($url, $data, 'DELETE');
$response = $request->send();
print_r($response);