PHP code example of jnilla / joomla-request-batcher

1. Go to this page and download the library: Download jnilla/joomla-request-batcher 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/ */

    

jnilla / joomla-request-batcher example snippets




// Process the batch
RequestBatcher::process(function($requestData){ // Callback for each request
    $requestData = json_decode($requestData); Parse the JSON string
    switch ($requestData->task){
			case 'getProductA':
			    // Some code here
			    $data = ['name'=> 'Product A' , 'value' => '$100'];
			    // The response must be string type. That is why we used json_encode()
			    $data = json_encode($data);
				return $data;
			case 'getProductB':
			    // Some code here
			    $data = ['name'=> 'Product B' , 'value' => '$350'];
			    $data = json_encode($data);
				return $data;
	}
});