rpungello / sdk-client
用于使用 Spatie 的 DTOs 进行数据传输的通用客户端,以创建基于 PHP 的 SDK
1.11.1
2024-09-20 19:15 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.7
- nesbot/carbon: ^2.68
- spatie/data-transfer-object: ^3.9
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- pestphp/pest: ^1.20
- spatie/ray: ^1.28
README
用于使用 Spatie 的 DTOs 进行数据传输的通用客户端,以创建基于 PHP 的 SDK。
安装
您可以通过 composer 安装此包
composer require rpungello/sdk-client
使用方法
实例化客户端
$client = new Rpungello\SdkClient('https://example.com');
GET 请求
// Returns a Psr\Http\Message\ResponseInterface response $response = $client->get('/api/v1/users'); // Specify a query string $response = $client->get('/api/v1/users', [ 'page' => 1, 'limit' => 10, ]); // Returns a json-decoded array from the response body $response = $client->getJson('/api/v1/users'); // Takes the JSON data returned and wraps it in a DTO for static typing $response = $client->getDto('/api/v1/users/1', UserDto::class); // Takes the JSON data returned and converts it to an array of DTOs for static typing $response = $client->getDtoArray('/api/v1/users', UserDto::class);
PUT/POST/PATCH 请求
// Returns a Psr\Http\Message\ResponseInterface response $response = $client->post('/api/v1/users', [ 'name' => 'John Doe', 'email' => 'john@example.com', ]); // Returns a json-decoded array from the response body $response = $client->postJson('/api/v1/users', [ 'name' => 'John Doe', 'email' => 'john@example.com', ]); // Takes the JSON data returned and wraps it in a DTO for static typing $user = new UserDto([ 'name' => 'John Doe', 'email' => 'john@example.com', ]); $response = $client->postDto('/api/v1/users', $user);
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。