PHP code example of roemerb / php7-rest

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

    

roemerb / php7-rest example snippets




use RestClient\RestClient;

$client = new RestClient(RestClient::HTTPS, 'api.myhost.com', ['version' => 2]);

$client->register('people', ['list', 'get', 'create']);
$client->registerMethod('people', [
	'name' 		=> 'address',
	'method' 		=> '{id}/formatted_address',
	'http_method'	=> RestClient::HTTP_GET // Or just 'GET'/'get'/'Get'
]);

/**
* This will call:
* GET https://api.myhost.com/people/v2/{id}
*/
$client->people->get($id);

// We can call custom methods the same way
$client->people->address($id);

class Person extends RestResource
{
	public function __construct()
	{
		// Just give the parent constructor some information
		parent::__construct($restClient, strtolower(__CLASS__);
	}
}

$people = new Person();
$people->get($id);

// Initiate an API call...
$client->people->get($id, function($response) {
	// Do something with $response
});

// ...and continue to do other stuff in the meantime.
shell
$token = Oauth::gen_token($credentials);

$client->addHeader('Authorization', 'Bearer ' . $token);