buqiu / microservices-request
Laravel microservices http request.
Installs: 2 042
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- laravel/framework: ^10.0
README
介绍
微服务 Http 请求系统扩展包。
环境
php >= 8.1
composer >= 2.0
使用
1.安装
composer require buqiu/microservices-request
2.发布 microservices.php 配置文件
php artisan vendor:publish --tag=buqiu-microservices-config
3.配置 .env 文件
MS_URI_PREFIX=URI 前缀 MS_USER=http://user_ms:8000
4.代码示例
4.1 依赖注入方式
use Buqiu\MicroservicesRequest\MicroservicesHttpService; public function __construct(MicroservicesHttpService $microservicesHttpService) { $this->microservicesHttpService = $microservicesHttpService; } public function index() { $user = $this->microservicesHttpService->setEndpoint('user')->get('user'); }
4.2 直接实例化方式
use Buqiu\MicroservicesRequest\MicroservicesHttpService; public function index() { $user = app(MicroservicesHttpService::class)->setEndpoint('user')->get('user'); } // 或 public function index() { $user = app(MicroservicesHttpService::class, ['serviceName' => 'user'])->get('user'); }