vasildakov/speedy
Composer 安装命令:
composer require vasildakov/speedy
包简介
Speedy API Client
README 文档
README
An easy to use PHP client for Speedy REST API
Speedy client is a PSR-7 and PSR-18 compliant HTTP client that implements Speedy communication protocol. It has clean and consistent API, is fully unit tested and even comes with an example application to get you started.
Features
This library is compliant with PSR-7: HTTP message interfaces, PSR-17: HTTP Factories and PSR-18: HTTP Client
Installation
Using Composer:
$ composer require vasildakov/speedy
Usage
The Configuration
Let's presume that you are using PHP dotenv to load environment variables
from a file named .env. In this case, you need to add the following variables:
SPEEDY_USERNAME="username"
SPEEDY_PASSWORD="password"
SPEEDY_LANGUAGE="EN"
The next step is to create a new Configuration instance like in the example bellow:
<?php // configuration $configuration = new Configuration( username: $_ENV['SPEEDY_USERNAME'], password: $_ENV['SPEEDY_PASSWORD'], language: $_ENV['SPEEDY_LANGUAGE'] );
Configuring Speedy Client
The final step is to configure the Speedy client.
The client can be configured with any PSR-18 HTTP Client and PSR-17 HTTP Factory:
Example with Guzzle and Laminas Diactoros
<?php use GuzzleHttp\Client; use Laminas\Diactoros\RequestFactory; $client = new Client(); // PSR-18 HTTP Client $factory = new RequestFactory(); // PSR-17 HTTP Factory $speedy = new Speedy($configuration, $client, $factory);
Example with Symfony HTTP Client and Nyholm HTTP Factory
<?php use Nyholm\Psr7\Factory\Psr17Factory; use Symfony\Component\HttpClient\Psr18Client; $client = new Psr18Client(); // PSR-18 HTTP Client $factory = new Psr17Factory(); // PSR-17 HTTP Factory $speedy = new Speedy($configuration, $client, $factory);
Making a Request
Once you have configured the client, you can proceed to make your first request. By default, each method returns the data in JSON, which can then be utilized as a simple PHP array or deserialized into the PHP model.
<?php // use an array $request = new GetContractClientsRequest(clientSystemId: "1234567"); $json = $speedy->getContractClient($request); $array = json_decode($json, true);
Processing the Response
The client API always returns the raw JSON response received from the endpoint. The JSON can be used as it is, decoded into a PHP associative array, or deserialized into a model object.
Deserialization can be achieved in two different ways: 1) by using the serializer, or 2) by decorating the original Speedy client with the SpeedyModelDecorator.
Using serializer:
<?php $json = $speedy->getContractClient($request); # json $serializer = (new SerializerFactory())(); # JMS\Serializer\SerializerInterface $response = $serializer->deserialize( data: $json, type: GetContractClientsResponse::class, format: 'json' ); # GetContractClientsResponse
Instead of calling the serializer every time, you can enhance the original Speedy client by decorating it with the SpeedyModelDecorator. This enhancement makes the responses more convenient, predictable and easy to use.
<?php $decorator = new SpeedyModelDecorator( new Speedy($configuration, $client, $factory) ); /** @var GetContractClientsResponse $response */ $response = $decorator->getContractClient(new GetContractClientsRequest());
Using the model
<?php // @var ArrayCollection $collection $collection = $response->getClients(); foreach ($collection as $client) { dump($client); # Model\Client dump($client->getClientName()); dump($client->getAddress()); # Model\Address dump($client->getAddress()->getSiteName()); # string dump($client->getAddress()->getPostcode()); # string }
Documentation
TBC
License
Code released under the MIT license
Speedy REST API examples
Speedy Web API Integration
vasildakov/speedy 适用场景与选型建议
vasildakov/speedy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「speedy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vasildakov/speedy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vasildakov/speedy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vasildakov/speedy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Speedy API Wrapper
A PSR-7 compatible library for making CRUD API endpoints
Collection of Listeners to log spec times, prioritise specs, and free memory after each spec
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
统计信息
- 总下载量: 84
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-29