PHP code example of adaiasmagdiel / cururu

1. Go to this page and download the library: Download adaiasmagdiel/cururu 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/ */

    

adaiasmagdiel / cururu example snippets




daiasMagdiel\Cururu\Cururu;

// Initialize Cururu with optional base URL and headers
$cururu = new Cururu('https://api.example.com', ['Authorization' => 'Bearer your_token']);

// Make a GET request
$response = $cururu->get('/resource');

// Get response content
if ($response->isSuccessful()) {
    echo $response->getContent();
} else {
    echo "Request failed with status: " . $response->getStatusCode();
}

// Make a POST request with JSON data
$response = $cururu->post('/resource', ['name' => 'Cururu'], ['Content-Type' => 'application/json']);

if ($response->isSuccessful()) {
    $json = $response->getJson();
    print_r($json);
}

$cururu = new Cururu();

// Make a GET request using the full URL
$response = $cururu->get('https://api.example.com/resource');

$cururu = new Cururu('https://api.example.com', ['Authorization' => 'Bearer your_token']);
$customHeaders = ['Custom-Header' => 'CustomValue'];

$response = $cururu->get('/resource', $customHeaders);

$data = ['name' => 'Cururu', 'description' => 'Simple HTTP client'];
$response = $cururu->post('/resource', $data, ['Content-Type' => 'application/json']);

if ($response->isSuccessful()) {
    echo "Resource created successfully!";
}

try {
    $response = $cururu->get('/invalid-endpoint');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

$response = $cururu->get('/resource');

// Get status code
$status = $response->getStatusCode();

// Get response content as JSON
$data = $response->getJson();

// Get specific header
$contentType = $response->getHeader('Content-Type');