PHP code example of naivic / curl

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

    

naivic / curl example snippets


$url = "http://openlibrary.org/search.json";
$needle = "Alice Wonderland";
$curl = new \Naivic\CURL();
$res = $curl->query( "GET", $url, [ "q" => $needle ] );
echo "Total time: ".$res["info"]["total_time"]." sec\n";
echo "Year: ".$res["data"]["docs"][0]["first_publish_year"]."\n";

$url = "https://api.restful-api.dev/objects";
$hdr = [ "Content-Type: application/json" ];
$hero = [
    "name" => "The Cat",
    "data" => [
        "type"     => "animal",
        "location" => "World",
    ],
];
$curl = new \Naivic\CURL();

$res = $curl->query( "POST", $url, $hero, $hdr );
$id = $res["data"]["id"];

$hero["data"] = [
    "type"     => "sapiens",
    "location" => "Wonderland",
];
$res = $curl->query( "PUT", $url."/".$id, $hero, $hdr );

$res = $curl->query( "PATCH", $url."/".$id, ["name" => "Alice"], $hdr );
print_r( $res["data"] );

$res = $curl->query( "DELETE", $url."/".$id, hdr: $hdr );

$res = $curl->query( "GET", $url."/".$id, hdr: $hdr );