PHP code example of solutionplus / microservice

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

    

solutionplus / microservice example snippets


Route::group([
    'middleware' => [
        'micro-service',
    ]
], function () {
    // routes communicates with other microservices goes here
});

// EX: $microserviceName = 'payment';
// EX: $uri = 'license-payments' || 'orders' ...etc;
// EX: $origin = 'payment.com';

// `$params` and `$data` should be ['key' => 'value'] pair array
// which represent query string in get requests or inputs in post requests

$response = MsHttp::get($microserviceName, $uri, $params = []);

$response = MsHttp::post($microserviceName, $uri, $data = []);

$response = MsHttp::put($microserviceName, $uri, $data = []);

$response = MsHttp::delete($microserviceName, $uri); // Not finished yet

$response = MsHttp::establish($microserviceName, $origin, $localPort);

# In kernel.php file


/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array<string, class-string|string>
 */
protected $routeMiddleware = [
    //
    'micro-service' => \Solutionplus\MicroService\Http\Middleware\MicroServiceMiddleware::class,
    'micro-service-establish-connection' => \Solutionplus\MicroService\Http\Middleware\MicroServiceEstablishConnectionMiddleware::class,
];
bash
php artisan config:cache