floweye / client
Floweye PHP API 客户端
v0.3
2024-01-30 12:21 UTC
Requires
- php: >=7.2
- ext-json: *
- contributte/utils: ^0.3.2 || ^0.4.0 || ^0.5.0
- guzzlehttp/guzzle: ^7.1.0
Requires (Dev)
- nette/di: ^2.4.15 || ^3.0.0
- ninjify/coding-standard: ^0.12.0
- phpstan/phpstan: ^0.12.0
- phpstan/phpstan-deprecation-rules: ^0.12.0
- phpstan/phpstan-nette: ^0.12.0
- phpstan/phpstan-strict-rules: ^0.12.0
- phpunit/phpunit: ^8.5.5
This package is auto-updated.
Last update: 2024-09-09 08:36:32 UTC
README
Floweye 的 PHP API 客户端 - REST API - 文档
版本
安装
使用 Composer 安装软件包。
composer require floweye/client
如何使用
高级
简单地注入所需的服务,这些服务允许您直接处理数据。
$userService = $context->getService(Floweye\Client\Service\UserService::class); $user = $userService->getById(1, []);
PSR-7 级别
如果您需要访问 PSR-7 响应,您可以使用我们的客户端层。
$userClient = $context->getService(Floweye\Client\Client\UserClient::class); /** @var Psr\Http\Message\ResponseInterface $response */ $response = $userClient->getById(1, []);
低级
此示例展示了手动服务实例化。
$guzzleFactory = $context->getService(Floweye\Client\Http\Guzzle\GuzzleFactory::class); $httpClient = $guzzleFactory->create([ 'base_uri' => 'https://floweye.tld/api/v1/', 'http_errors' => false, 'headers' => [ 'X-Api-Token' => 'floweye-api-key', ] ]); // You can now use $httpClient with our Clients, Services or on its own $userClient = new Floweye\Client\Client\UserClient($httpClient); $userService = new Floweye\Client\Service\UserService($userClient);
Nette 桥接
extensions: # For Nette 3.0+ floweye.api: Floweye\Client\DI\FloweyeExtension # For Nette 2.4 floweye.api: Floweye\Client\DI\FloweyeExtension24 floweye.api: debug: %debugMode% http: base_uri: https://floweye.tld/api/v1/ headers: X-Api-Token: floweye_api_key
在 http
选项下配置默认 HTTP 客户端 Guzzle HTTP 客户端。
API 端点概述
ApplicationService
UserService
UserGroupService