PHP code example of faysoft / feignphp

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

    

faysoft / feignphp example snippets


use Kuabound\FeignPHP\FeignClient;

// 假设已设置好 NACOS_ADDR、NACOS_NAMESPACE_ID 环境变量

$client = FeignClient::make('your-service-name');

// 获取业务数据
try {
    // GET 请求
    $data = $client->get('/api/path', ['foo' => 'bar']);
    
    // POST 请求
    $data = $client->post('/api/path', ['key' => 'value']);
    // 处理 $data
    // ...
} catch (\Kuabound\FeignPHP\exception\FeignClientException $e) {
    // 自定义异常处理,或直接不套try catch,往外抛,看业务场景
}