PHPackages                             printzhucheng/curl-http-package - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. printzhucheng/curl-http-package

ActiveLibrary[HTTP &amp; Networking](/categories/http)

printzhucheng/curl-http-package
===============================

A simple and powerful cURL HTTP client for PHP

00PHP

Since Apr 28Pushed 2mo agoCompare

[ Source](https://github.com/printzhucheng/curl-http-package)[ Packagist](https://packagist.org/packages/printzhucheng/curl-http-package)[ RSS](/packages/printzhucheng-curl-http-package/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Curl HTTP Package
=================

[](#curl-http-package)

A simple and powerful cURL HTTP client for PHP. Supports GET, POST, PUT, PATCH, DELETE requests, JSON handling, file uploads, and more.

Installation
------------

[](#installation)

```
composer require printzhucheng/curl-http-package
```

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- cURL extension

Quick Start
-----------

[](#quick-start)

```
use Printzhucheng\CurlHttpPackage\CurlHttpClient;

// Create client instance
$client = new CurlHttpClient();

// Simple GET request
$response = $client->get('https://api.example.com/users');
echo $response->getBody();

// With query parameters
$response = $client->get('https://api.example.com/users', ['page' => 1, 'limit' => 10]);

// Check if successful
if ($response->isSuccessful()) {
    $data = $response->json();
    print_r($data);
}
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

```
$client = new CurlHttpClient([
    'base_url' => 'https://api.example.com',
    'timeout' => 60,
    'verify_ssl' => true,
    'headers' => [
        'Accept' => 'application/json',
        'X-API-Key' => 'your-api-key'
    ]
]);
```

### GET Request

[](#get-request)

```
// Simple GET
$response = $client->get('/users');

// With query parameters
$response = $client->get('/users', ['status' => 'active', 'role' => 'admin']);

// With custom headers
$response = $client->get('/users', [], ['Authorization' => 'Bearer token']);
```

### POST Request

[](#post-request)

```
// Form data
$response = $client->post('/users', ['name' => 'John', 'email' => 'john@example.com']);

// JSON data
$response = $client->postJson('/users', ['name' => 'John', 'email' => 'john@example.com']);

// Raw body
$response = $client->post('/api/endpoint', '{"key":"value"}', ['Content-Type' => 'application/json']);
```

### PUT Request

[](#put-request)

```
// Form data
$response = $client->put('/users/1', ['name' => 'John Updated']);

// JSON data
$response = $client->putJson('/users/1', ['name' => 'John Updated']);
```

### PATCH Request

[](#patch-request)

```
$response = $client->patch('/users/1', ['status' => 'inactive']);
```

### DELETE Request

[](#delete-request)

```
$response = $client->delete('/users/1');
```

### File Upload

[](#file-upload)

```
// Single file
$response = $client->upload('/upload', 'file', '/path/to/file.jpg');

// File with additional data
$response = $client->upload('/upload', 'file', '/path/to/file.jpg', ['user_id' => 1, 'type' => 'avatar']);
```

### Working with Response

[](#working-with-response)

```
$response = $client->get('/users/1');

// Get status code
$statusCode = $response->getStatusCode();

// Get body as string
$body = $response->getBody();

// Get body as JSON (array)
$data = $response->json();

// Get body as JSON (object)
$data = $response->json(false);

// Get all headers
$headers = $response->getHeaders();

// Get specific header
$contentType = $response->getHeader('Content-Type');

// Check response status
if ($response->isSuccessful()) {
    // 2xx response
}

if ($response->isOk()) {
    // 200 response
}

if ($response->isCreated()) {
    // 201 response
}

if ($response->isClientError()) {
    // 4xx response
}

if ($response->isServerError()) {
    // 5xx response
}

if ($response->isNotFound()) {
    // 404 response
}
```

### Fluent Interface

[](#fluent-interface)

```
$client = new CurlHttpClient();

$client->setBaseUrl('https://api.example.com')
       ->setTimeout(60)
       ->setVerifySsl(false)
       ->addDefaultHeader('Authorization', 'Bearer token')
       ->addDefaultHeader('Accept', 'application/json');

$response = $client->get('/users');
```

### Error Handling

[](#error-handling)

```
use Printzhucheng\CurlHttpPackage\CurlHttpClient;
use RuntimeException;

try {
    $client = new CurlHttpClient(['timeout' => 5]);
    $response = $client->get('https://api.example.com/users');

    if (!$response->isSuccessful()) {
        echo "Request failed with status: " . $response->getStatusCode();
    }
} catch (RuntimeException $e) {
    echo "cURL error: " . $e->getMessage();
}
```

API Reference
-------------

[](#api-reference)

### CurlHttpClient

[](#curlhttpclient)

MethodDescription`get(string $url, array $params = [], array $headers = [])`Send GET request`post(string $url, $data = [], array $headers = [])`Send POST request`postJson(string $url, array $data, array $headers = [])`Send POST request with JSON body`put(string $url, $data = [], array $headers = [])`Send PUT request`putJson(string $url, array $data, array $headers = [])`Send PUT request with JSON body`patch(string $url, $data = [], array $headers = [])`Send PATCH request`delete(string $url, array $headers = [])`Send DELETE request`upload(string $url, string $field, string $filePath, array $additionalData = [], array $headers = [])`Upload file`request(string $method, string $url, $data = [], array $headers = [])`Send custom request`setBaseUrl(string $baseUrl)`Set base URL`setTimeout(int $seconds)`Set timeout`setVerifySsl(bool $verify)`Set SSL verification`setDefaultHeaders(array $headers)`Set default headers`addDefaultHeader(string $name, string $value)`Add default header`getLastRequestInfo()`Get last request info### Response

[](#response)

MethodDescription`getStatusCode()`Get HTTP status code`getBody()`Get response body as string`json(bool $assoc = true)`Get response body as JSON`getHeaders()`Get all response headers`getHeader(string $name)`Get specific header`isSuccessful()`Check if 2xx response`isOk()`Check if 200 response`isCreated()`Check if 201 response`isClientError()`Check if 4xx response`isServerError()`Check if 5xx response`isNotFound()`Check if 404 responseLicense
-------

[](#license)

MIT License

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance56

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/384b78bea561195db52c2edcbfd46067fe04995f8708b44c106c26bc0ebb735c?d=identicon)[ZHCHcom255090](/maintainers/ZHCHcom255090)

---

Top Contributors

[![printzhucheng](https://avatars.githubusercontent.com/u/96102841?v=4)](https://github.com/printzhucheng "printzhucheng (2 commits)")

### Embed Badge

![Health badge](/badges/printzhucheng-curl-http-package/health.svg)

```
[![Health](https://phpackages.com/badges/printzhucheng-curl-http-package/health.svg)](https://phpackages.com/packages/printzhucheng-curl-http-package)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25026.1M82](/packages/php-http-cache-plugin)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k122](/packages/httpsoft-http-message)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)[swoft/websocket-server

swoft websocket server component

16135.7k5](/packages/swoft-websocket-server)[thesis/nats

Async (fiber based) client for Nats.

754.4k](/packages/thesis-nats)[jasny/http-signature

Implementation of the IETF HTTP Signatures draft RFC

10104.7k](/packages/jasny-http-signature)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
