PHP code example of phplicengine / phplicengine-api
1. Go to this page and download the library: Download phplicengine/phplicengine-api 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/ */
phplicengine / phplicengine-api example snippets
use PHPLicengine\Api\Api;
$api = new Api();
// If your RESTApi server pi-Key");
// SSL verification is enabled by default. You can use below to disable it.
// $api->disableSslVerification();
// You can use below to enable it again.
// $api->enableSslVerification();
// timeout is set to 30 by default. You can use below to change it if needed.
// $api->setTimeout(60);
// Sets the host:port of a proxy to be used by cURL. If this is not set,
// no proxy is used. For example, $api->setCurlProxy('proxy.example.com:3128');
// $api->setCurlProxy($proxy);
// get(), post(), delete(), put(), patch() methods are available.
// first parameter is url, second is query as array, third is header as array.
// Only first parameter (i.e. $url) is ValidResponse()) {
if ($response->isError()) { // if response of api has error
print($response->getErrorMessage());
} else {
// $dataAsObject = $response->getDecodedJson();
// echo $dataAsObject->username;
// echo $response->getContentType();
// You can get X-ApiServer-Response header value like below:
// echo $response->getReference();
print("<pre>");
print_r($response->getJsonAsArray());
}
} else {
print("Invalid server response.");
}
} else { // response code is not 200:Ok
die("Error ".$response->getResponseCode()." : ".$response->getReasonPhrase());
}
} else { // api curl Error occurs.
die("Curl Connection: ".$api->getCurlErrno()." : ".$api->getCurlError());
}
// for logging purposes only:
print($api->getResponse());
print_r($api->getRequest());
// Sets the host:port of a proxy to be used by cURL. If this is not set,
// no proxy is used. For example, $api->setCurlProxy('proxy.example.com:3128');
$api->setCurlProxy($proxy);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.