PHP code example of jessesoeteman / api-handler

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

    

jessesoeteman / api-handler example snippets




use APIHandler\APIHandler;

$apiHandler = new APIHandler(get_request);

$apiHandler->addError("error 1");
$apiHandler->addError("error 2");

$apiHandler->addError("error 3", true); // <-- Exits here

$apiHandler->addError("error 4");
 
$apiHandler->addError("error 1");
$apiHandler->addError("error 2");
$apiHandler->addError("error 3");

$apiHandler->APIExitOnError(); // <-- Exits here

$apiHandler->addError("error 4");
$apiHandler->addData([]);
$apiHandler->APIExit();

$apiHandler->addError("error 1");
$apiHandler->addError("error 2");
$apiHandler->addError("error 3");

$apiHandler->addData([]);

$apiHandler->APIExit(); // <-- Exits here

if (false) {
    $apiHandler->addError("error 1"); // Error wont be added.
}
$apiHandler->APIExitOnError(); // <-- Does not exit because there is no error.

$apiHandler->addData({});
$apiHandler->addData([]);
$apiHandler->addData("Hello World!");

$apiHandler->APIExit(); // <-- Exits here