PHP tool to connect to a REST API using design pattern Singleton and inheritance OOP.
This PHP tool is tested and working just fine. It makes your life really easy to connect and process information to a REST API with no extra packages or libraries.
It was created as a coding exercise applying Inheritance OOP (Object-oriented programming) and design pattern Singleton. It uses CURL to handle all the processes.
To use it is very simple, you can either directly download the project or use composer. There are no external dependencies.
If you decide to use composer just type:
composer require bruno-canada/php-restclient-easytouse
PHP 5.5+
CURL mod enabled
Check the file "testing.php" or a real ready-to-use example below:
$endpointRoot = "https://restcountries.eu/rest/v2/";
$endpoint = $endpointRoot . "name/brazil";
try {
$getSales = EASYREST\APIClient::get($endpoint);
print_r($getSales);
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}
- [PHP] (https://www.php.net/) PHP
- [CURL] (https://curl.haxx.se/) Transfering Data via CURL