PHP code example of weblabnl / curl

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

    

weblabnl / curl example snippets


$params = [
    first_name  => 'Ankie',
    last_name   => 'Visser'
];

$url = 'https://api.weblab.nl/users';

$result = Weblab\CURL\CURL::setBearer('some_access_token')
    ->post($url, $params);
    
if ($result->getStatus() === 201) {
    // User created        
}    

$url = 'https://api.weblab.nl/users/1';

$params = [
    '[email protected]'
];

$request = (new Weblab\CURL\Request())
    ->setOption(CURLOPT_URL, $url)
    ->setOption(CURLOPT_POSTFIELDS, http_build_query($params))
    ->setOption(CURLOPT_CUSTOMREQUEST, 'PATCH')
    ->setOption(CURLOPT_POST, true)
$result = $request->run();

if ($result->getStatus() === 200) {
    // user successfully saved            
}

$result = Weblab\CURL\CURL::get('https://api.weblab.nl/users', ['limit' => '1']);

/**
 * cURL result body:
 * {
 *     data: [
 *         {
 *             id           : 1 ,
 *             first_name   : "Ankie",
 *             last_name    : "Visser"
 *         }
 *     ]
 * }
 */

if ($result->getStatus() === 200) {
    foreach ($result->getResults()->data as $user) {
        // $user object
    }
}

$result = Weblab\CURL\CURL::doesFileExist('https://www.weblab.nl/img/logo.png')
if ($result) {
    // file exists
}