PHP code example of alicfeng / service-client

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

    

alicfeng / service-client example snippets



return [
    'arrangement' => [
        'success_code' => 1000,
    ],
    // 协议驱动 HTTP
    'http'        => [
        // 路由列表
        'routes' => [
            // 服务路由 服务名称.路由别名
            'user.profile' => [
                'uri'     => '/api/user',
                'method'  => 'GET',
                'headers' => [
                ],
            ],
        ],
        // 服务分组 配置每组服务通用配置
        'groups' => [
            'user' => [
                'timeout'  => 60,
                'base_uri' => env('SERVICE_CLIENT_USER_SERVER_BASE_URI'),
                'verify'   => env('SERVICE_CLIENT_USER_SERVER_VERIFY', false),
                'headers'  => [
                ],
            ],
        ],
    ],
];

use Samego\Client\Facades\ServiceHttpClient;

// 简单请求
ServiceHttpClient::service('user.profile')->request();

// 复杂请求
ServiceHttpClient::service('user.profile')->package(['name'=>'samego'])->header(['Auth'=>'token'])->uri('api/user/profile')->request();
shell
php artisan vendor:publish --provider="Samego\Client\ServiceProvider\ServiceClientProvider"