PHP code example of phprise / http-value-object
1. Go to this page and download the library: Download phprise/http-value-object 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/ */
phprise / http-value-object example snippets
use Phprise\Http\ValueObject\Headers;
$headers = new Headers([
'Content-Type' => ['application/json']
]);
// Immutably add a header
$newHeaders = $headers->with('Authorization', 'Bearer token');
if ($newHeaders->has('authorization')) {
$values = $newHeaders->get('authorization');
}
$array = $newHeaders->toArray();
use Phprise\Http\ValueObject\Uri;
$uri = new Uri('https://api.example.com/v1/users?query=otaku');
echo $uri->getHost(); // api.example.com
echo $uri->getPath(); // /v1/users
// Immutably change the path
$newUri = $uri->withPath('/v2/users');