定制 borschphp/http-client 二次开发

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

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

borschphp/http-client

最新稳定版本:1.1.0

Composer 安装命令:

composer require borschphp/http-client

包简介

A minimal PSR-18 HTTP Client.

README 文档

README

A minimalist PSR-18 implementation for making HTTP requests in PHP.

Installation

The package can be installed via Composer.
Run the following command:

composer require borschphp/http-client

Usage

Here's a simple example of how to use the Borsch HTTP Client:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Borsch\Http\Client;
use Borsch\Http\Adapter\Curl;
use Laminas\Diactoros\{RequestFactory, ResponseFactory, StreamFactory};

$adapter = new Curl(new ResponseFactory(), new StreamFactory());
$client = new Client($adapter);

$request = (new RequestFactory())->createRequest(
    'GET',
    'https://jsonplaceholder.typicode.com/posts/1'
);

$response = $client->sendRequest($request);

echo $response->getBody();

Middlewares

Before

You can add middleware that will be executed before the request is sent:

$adapter = new Curl(new ResponseFactory(), new StreamFactory());
$client = new Client($adapter);

$client
    ->before(function (RequestInterface $request, AdapterInterface $adapter) {
        // For instance, fetch a JWT Token and add it to the request headers
        $token = get_jwt_token_from_cache_or_auth_service();
        
        return $request->withHeader('Authorization', 'Bearer ' . $token);
    })

After

You can also add middleware that will be executed after the response is received:

$client
    ->after(function (ResponseInterface $response, RequestInterface $request) {
        // For instance, log the response status code, add a header, modify the body, etc.
        error_log('Response Status Code: ' . $response->getStatusCode());
        
        return $response->withHeader('X-Processed-Time', time());
    });

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-24