allissonaraujo/sugardata

A simple Package to facilitate the use of requests with PHP

dev-main 2024-07-23 19:26 UTC

This package is auto-updated.

Last update: 2025-06-23 21:51:40 UTC


README

sugardata

A simple PHP package to send and receive HTTP requests using the cURL library.

Installation

To install this package, use Composer:

composer require allissonaraujo/sugardata:dev-main

Usage

Sending a POST request ⬆️

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

Sending a GET Request ⬇️

To send a GET request, you can specify the method as 'GET':

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

Sending a PUT Request 🔄

Here's an example of how to send a PUT request:

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

Sending a DELETE Request ⛔

And here's how to send a DELETE request:

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