hitraa/openforge-curl

A modern, open-source PHP cURL-based HTTP request handler for OpenForge projects and general use.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/hitraa/openforge-curl

1.0.0 2025-06-21 21:25 UTC

This package is auto-updated.

Last update: 2025-12-21 23:57:33 UTC


README

A modern, open-source PHP cURL-based HTTP request library designed for simplicity, flexibility, and clean abstraction of HTTP requests.

✨ Features

  • ✅ Simple, object-oriented API
  • ✅ Supports GET, POST, PUT, PATCH, DELETE, HEAD
  • ✅ JSON and raw body support
  • ✅ Query parameter builder
  • ✅ Bearer token support
  • ✅ Flexible headers and options
  • ✅ PSR-4 autoloading
  • ✅ Easily testable

📦 Installation

Use Composer:

composer require hitraa/openforge-curl

🚀 Usage

🔍 GET request with query parameters

use OpenForge\Curl\HttpRequest;

$response = (new HttpRequest('https://httpbin.org/get'))
    ->setMethod('GET')
    ->setData(['q' => 'openforge'])
    ->responseArray();

print_r($response);

📤 POST request with JSON body

$response = (new HttpRequest('https://httpbin.org/post'))
    ->setMethod('POST')
    ->setJson([
        'username' => 'harshal',
        'role' => 'admin'
    ])
    ->responseObject();

🧾 POST raw body

$response = (new HttpRequest('https://httpbin.org/post'))
    ->setMethod('POST')
    ->setRaw('<xml><user>Harshal</user></xml>')
    ->addHeader('Content-Type: application/xml')
    ->responseText();

🔐 Bearer Authentication

$response = (new HttpRequest('https://api.example.com/secure'))
    ->setMethod('GET')
    ->setBearer('your-token-here')
    ->responseArray();

Here's a clean and professional README block you can insert under your Usage or Advanced section to explain the sslVerify(false) feature:

🔐 Disable SSL Verification (for testing only)

If you're working in a local development environment, unsecured server or dealing with self-signed certificates, you may want to disable SSL verification temporarily:

$response = (new HttpRequest('https://self-signed.local/api'))
    ->setMethod('GET')
    ->sslVerify(false) // ⚠️ disables certificate & hostname verification
    ->responseArray();

⚠️ Warning: Disabling SSL verification is not recommended for production use. It makes your HTTP client vulnerable to MITM (Man-in-the-Middle) attacks.

🧪 Auto-disable SSL for Local/Test Environment

You can optionally disable SSL verification based on an environment variable:

$response = (new HttpRequest('https://dev.api'))
    ->setMethod('GET')
    ->sslAuto(); // disables SSL if APP_ENV = local or testing

OR

// Explicitly set APP_ENV
putenv("APP_ENV=local");

// Do https cURL request
$response = (new HttpRequest('https://dev.api'))
    ->setMethod('GET')

By default, it checks APP_ENV for local or testing.
You may also customize:

->sslAuto('MY_ENV', ['dev', 'staging'])

⚠️ This doesn't load a .env file — you must ensure environment variables are set manually or via your framework.

🧪 Testing

Run tests via PHPUnit:

vendor/bin/phpunit

# running test on local machine
APP_ENV=local vendor/bin/phpunit

Make sure phpunit.xml is at the root of the project.

📁 Project Structure

openforge-curl/
├── src/                  # Library source code
│   └── HttpRequest.php
├── tests/                # Unit tests
│   └── HttpRequestTest.php
├── composer.json
├── phpunit.xml
├── .gitignore
├── .gitattributes
└── README.md

🧑‍💻 Author

Harshal Khairnar
Founder, Hitraa Technologies
📧 harshal@hitraa.com

📄 License

MIT License © 2025 Hitraa Technologies