exewen/http

A http component for Exewen.

v0.1.6 2024-04-17 13:26 UTC

This package is auto-updated.

Last update: 2024-04-17 13:36:34 UTC


README

composer require exewen/http

复制配置

cp -rf ./publish/exewen /your_project/config

初始化

!defined('BASE_PATH_PKG') && define('BASE_PATH_PKG', dirname(__DIR__, 1));

请求

# 初始化DI
$app = new Container();
$app->setProviders([LoggerProvider::class,LoggerProvider::class]);
$this->app = $app;
/** @var HttpClientInterface $http */
$http = $this->app->get(HttpClientInterface::class);

# get
$response = $http->get('nacos', '/nacos/v1/cs/configs', [
    'dataId' => $this->dataId,
    'group' => $this->group,
    'tenant' => $this->namespaceId,
]);

# post
$response = $http->post('nacos', '/nacos/v1/ns/instance', [
    'namespaceId' => $this->namespaceId,
    'serviceName' => $this->serviceName,
    'groupName' => $this->group,
    'ip' => '10.0.2.143',
    'port' => 8081,
    'metadata' => json_encode([
        'ver' => "1.0.0"
    ], JSON_UNESCAPED_UNICODE),
]);