PHP code example of vzool / url

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

    

vzool / url example snippets




use vzool\URL\URL;

$http = new URL('https://jsonplaceholder.typicode.com');

// to GET

$result = $http->GET('/posts/1');

// to POST

$result = $http->POST('/posts', [
  "title" => "Agreement",
  "body" => "Ha ha ha",
  "author" => "Aziz",
]);

// to PUT

$result = $http->PUT('/posts/1', [
  "title" => "Agreement #2",
]);

// to DELETE

$result = $http->DELETE('/posts/1');

// or

$result = $http->delete('/posts/1');

// to get result

print_r($result->content()); // returns stdClass objects :)
print_r($result->toArray()); // returns array
print_r($result->toJson());  // returns raw response, I'm a JSON Patriot ;)