定制 timostamm/json-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

timostamm/json-client

Composer 安装命令:

composer require timostamm/json-client

包简介

A simple client for JSON APIs using Guzzle and the Symfony Serializer.

README 文档

README

build Packagist PHP Version GitHub tag License

A simple client for JSON APIs using Guzzle and the Symfony Serializer.

To implement a API client, you can extend AbstractApiClient and write your methods, using the Guzzle Http Client to transmit.

class MyClient extends AbstractApiClient {
    
    
    /**
     * @throws TransferException
     */
    public function send(Model $model):void
    {
        // The data will automatically be 
        // serialized to JSON. 
        $this->http->post('model', [
            'data' => $model
        ]);
    }
    
    
    /**
     * @param int $id
     * @throws TransferException
     * @returns Model 
     */
    public function get(int $id):Model
    {
        $response = $this->http->get('model/'.$id, [
            'deserialize_to' => Model::class
        ]);

        if (!$response instanceof DeserializedResponse) {
            throw new \RuntimeException('Expected a DeserializedResponse, got: '.get_class($response));
        }

        return $response->getDeserializedData();
    }


}

All functionality is implemented as middleware, the AbstractApiClient just configures the Guzzle HandlerStack for you.

Provided middleware

Serialization

See DeserializeResponseMiddleware and SerializeRequestBodyMiddleware.

Server error messages

ServerMessageMiddleware provides support for JSON error messages.

Response expectations

If you want to make sure that a response has a specific header, content type or other feature, use ResponseExpectationMiddleware.

Logging

There is also middleware to log all HTTP requests (and corresponding response or exception), see HttpLoggingMiddleware

An adapter for Psr\Log\LoggerInterface is available.

This middleware is not added by default because the order is important: The HttpLoggingMiddleware must be added last.

统计信息

  • 总下载量: 235
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固