定制 weblabel/http-client 二次开发

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

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

weblabel/http-client

最新稳定版本:v1.1.1

Composer 安装命令:

composer require weblabel/http-client

包简介

HTTP client wrapper

README 文档

README

Github CI

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Open a command console, enter your project directory and execute:

$ composer require weblabel/http-client

This package uses PSR-7, PSR-17 and PSR-18 interfaces, but does not provide their implementations, so you have to install libraries that implements those.

Recommended libraries:

$ composer require nyholm/psr7
$ composer require symfony/http-client

Basic Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;
use Weblabel\HttpClient\HttpClient;
use Weblabel\HttpClient\RequestFactory;
use Weblabel\HttpClient\Factory\JsonRequestFactory;

$symfonyClient = new Psr18Client();
$httpClient = new HttpClient($symfonyClient);
$psrFactory = new Psr17Factory();
$jsonRequestFactory = new JsonRequestFactory($psrFactory, $psrFactory);

$simpleClient = new SimpleClient('https://example.com', $httpClient, $jsonRequestFactory);
$statusResponse = $simpleClient->getStatus();

class SimpleClient
{
    private ClientInterface $client;
    private RequestFactory $requestFactory;
    private string $baseUri;

    public function __construct(string $baseUri, ClientInterface $client, RequestFactory $requestFactory)
    {
        $this->client = $client;
        $this->requestFactory = $requestFactory;
        $this->baseUri = $baseUri;
    }

    public function getStatus(): ResponseInterface
    {
        $request = $this->requestFactory->get($this->baseUri . '/status');

        return $this->client->sendRequest($request);
    }
}

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-22