This topic is locked
[SOLVED]

Fallback functionality for REST API connections providing autofill values

1/7/2022 3:47:06 PM
PHPRunner General questions
mbintex author

I am using some REST API as input for AJAX based autofill lists. For example ZIP Codes/Towns via Rest API as Autocomplete in a ZIP field and then fill town in as well.

All this works well with the functionality of PHPRunner.

But know I´d like to be prepared for the case, that the REST API does not work or is not available (for what reason ever) that I get some kind of fallback functionality. Currently you only get a big red PHP error, if the REST API is offline, does not respond or does not allow the request. But I would like to be able to work even then with my solutions. Manually editing ZIP codes and towns would be fine, if the API server does not respond.

I tried to accomplish this, by manually editing the PHPrunner generated code. Instead of the false message I would like to provide an empty array or small set of values. But until now I only get different error messages with some error 256 in classes/datasource/rest.php

Any help would be appreciated.

mbintex author 1/15/2022

So far, this seems the best way to go:

// do the API request
$response = $dataSource->getConnection()->requestJson( $url, $method );
print_r($response);
if( $response === false ) {
// something went wrong
// $dataSource->setError( $dataSource->getConnection()->lastError() );
// return false;

$response=array("data"=>array(0=>array ("Titel"=>"Red", "Seite"=>"Green", "Text"=>"Blue"),1=>array ("Titel"=>"Apple", "Seite"=>"Orange", "Text"=>"Grapes"),2=>array ("Titel"=>"BMW","Seite"=>"Skoda", "Text"=>"Mercedes")));
}

Instead of returning an error a helper array is generated and sent.