maxiwheat/httpful

一个易读、可链式调用、REST友好的PHP HTTP客户端

0.4.0 2023-04-05 19:33 UTC

This package is not auto-updated.

Last update: 2024-09-20 01:07:38 UTC


README

分支

需要PHP 8.1或更高版本。

安装

{
  "require": {
    "maxiwheat/httpful": "^0.4"
  }
}

本地开发

docker compose run --rm httpful bash

# In the container shell

# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Run phpstan
vendor/bin/phpstan analyse src
vendor/bin/phpstan analyse tests

Httpful

Total Downloads

Httpful是一个为PHP 7.2+设计的简单HTTP客户端库。它强调可读性、简洁性和灵活性——基本上提供完成任务所需的功能和灵活性,并且使这些功能的使用变得非常简单。

特性

  • 支持易读的HTTP方法(GET、PUT、POST、DELETE、HEAD、PATCH和OPTIONS)
  • 自定义头
  • 自动“智能”解析
  • 自动负载序列化
  • 基本认证
  • 客户端证书认证
  • 请求“模板”

预览

这里有一件能引起你兴趣的事情。搜索包含“#PHP”的推文。随意添加一个简单的头。注意,库会自动将响应解释为JSON(如果需要,可以覆盖此设置)并将其解析为对象数组。

// Make a request to the GitHub API with a custom
// header of "X-Trvial-Header: Just as a demo".
$url = "https://api.github.com/users/maxiwheat";
$response = src\Request::get($url)
    ->expectsJson()
    ->withXTrivialHeader('Just as a demo')
    ->send();

echo "{$response->body->name} joined GitHub on " .
                        date('M jS', strtotime($response->body->created_at)) ."\n";

安装

Composer

Httpful符合PSR-0标准,可以使用composer安装。只需将maxiwheat/httpful添加到你的composer.json文件中。Composer是PEAR的合理替代品。它非常适合管理大型项目中的依赖关系

{
  "require": {
    "maxiwheat/httpful": "*"
  }
}

贡献

Httpful强烈鼓励提交pull请求。在提交pull请求时,请

  • 所有pull请求应针对dev分支(而非master
  • 确保你的代码遵循编码规范
  • 请使用软制表符(四个空格)而不是硬制表符
  • 确保为你的更改添加适当的测试覆盖率
  • 通过phpunit ./tests在测试目录中运行所有单元测试
  • 在适当的地方包含注释,并添加描述性的pull请求消息