PHP code example of uniondrug / service

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

    

uniondrug / service example snippets


return [
    'default' => [
        ......
        'providers'           => [
            ......
            \Uniondrug\Service\ServiceServiceProvider::class,
        ],
    ],
];

public function postAction()
{
    $serviceName = 'serviceName';
    $route = '/route/action';
    $query = ["page" => 1];
    $body = ["userId" => 1, "options" => ["key" => "value"]];
    $return = $this->serviceClient->post($serviceName, $route, $query, $body);

    print_r($return->data());
}

public function postAction()
{
    // codes ignored
    $this->serviceServer->withError("错误原因", 1);
}