jdwx/json-api-client
最新稳定版本:v1.2.5
Composer 安装命令:
composer require jdwx/json-api-client
包简介
A simple JSON API client and supporting tools.
README 文档
README
A simple PHP module for interacting with JSON API services.
Installation
You can require it directly with Composer:
composer require jdwx/json-api-client
Or download the source from GitHub: https://github.com/jdwx/json-api-client.git
Requirements
This module requires PHP 8.3 or later. The implementation depends on the excellent Guzzle HTTP client implementation, which provides all the needed features for extended streaming support. It also requires the JSON extension.
Usage
Here is a basic usage example:
$client = JDWX\JsonApiClient\HttpClient::withGuzzle( 'https://api.example.com' ); $rsp = $client->request( 'GET', '/v1/resource' ); if ( ! $rsp->isSuccess() ) { $uStatus = $rsp->status(); echo "{$uStatus} Error: ", $rsp->body(), "\n"; exit( 1 ); } if ( ! $rsp->isJson() ) { $stContentType = $rsp->getOneHeader( 'content-type' ) ?? 'none'; echo "Error: Expected JSON content-type, got: {$stContentType}\n"; exit( 1 ); } $data = $rsp->json(); var_dump( $data );
There is also 100% test coverage for this module, which provides additional examples of usage.
Stability
This module is considered stable and is used in production code. However, it was newly-developed in 2024 based on multiple previous implementations, so it hasn't received the same level of testing and extensive use as some of the other modules in this suite. That said, it successfully processes hundreds of thousands of API calls per day.
History
This module was refactored out of four separate existing modules for interacting with JSON APIs in a larger codebase. It has been rewritten essentially from scratch. It was initially released in 2024.
统计信息
- 总下载量: 387
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-24