chaoswd/http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

chaoswd/http

最新稳定版本:1.1.0

Composer 安装命令:

composer require chaoswd/http

包简介

README 文档

README

chaoswd/http is a lightweight HTTP client wrapper for PHP that simplifies making GET and POST requests using native cURL.
It provides simple methods for sending requests and returning structured responses as a string, objects or arrays.

🚀 Installation

Install via Composer:

composer require chaoswd/http

🧩 Basic Usage

<?php

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

use Chaos\Http\Http;

$http = new Http();

// Basic GET request
$response = $http->get('https://jsonplaceholder.typicode.com/todos/1');

// $response is now a response object - use `json()`, `object()`, or `array()` for which response type you want.
var_dump($response->json());

⚙️ Features

  • Simplified wrapper around PHP’s native cURL
  • Supports GET, POST methods
  • Handles headers and query parameters
  • Configurable timeout

Example POST request:

$response = $http->post('https://example.com/api/posts', [
    'title' => 'Chaos Framework',
    'body'  => 'Lightweight HTTP client test',
]);

📚 Methods

Method Description
get(string $url, array $params = []) Send a GET request
post(string $url, array $data = []) Send a POST request
withHeaders(array $headers) Set request headers
withTimeout(int $seconds) Set request timeout
headers() Return headers
json() Return a JSON string
object() Parse JSON as objects
array() Parse JSON as arrays

🧾 Example: Custom Headers

$http = new Chaos\Http\Http();

$http->withHeaders([
    'Authorization' => 'Bearer YOUR_TOKEN_HERE',
    'Accept' => 'application/json'
]);

$response = $http->get('https://api.example.com/user')->json();

🧰 Requirements

  • PHP 8.2+
  • cURL extension enabled

🪪 License

Released under the MIT License.

© 2025 Chaos Web Development & Jordan Gerber

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-14